amaork / libi2c Goto Github PK
View Code? Open in Web Editor NEWLinux i2c library, support C/C++/Python
License: MIT License
Linux i2c library, support C/C++/Python
License: MIT License
redefinition of ‘union i2c_smbus_data’
redefinition of ‘struct i2c_msg’
FIXED by comment #include <linux/i2c.h> in src/i2c.h
I am trying to connect Adafruit VL53L4CD Time of Flight Sensor (https://www.adafruit.com/product/5396) with Nvidia Jetson Xavier NX using libi2c. But I could not figure out how to do it. Any one have any experience using VL53L4CD?
I found some code for Arduino https://github.com/stm32duino/VL53L4CD. This code should have the information for the device, such as address etc.
Dear,
I found error in python3.10
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Reference by this
https://peps.python.org/pep-0353/
https://bugs.python.org/issue40943
After I add
#define PY_SSIZE_T_CLEAN 1
In the first line of 'src/pyi2c.c,' the library can work. Could you please review the source code again to ensure that other variables are also working fine?
I am having trouble using "i2c_ioctl_write" and "i2c_ioctl_read" in the same script.
If I use only one of them, does not matter which one, it was great. It reads when I aske it to do so, and it writes when I want it to do.
However, if I try to write and read (both in the same script), it does not work as it has to do. I have tried opening a bus, writing and closing it and afterwards opening the bus again to read the data, but it does not work either.
Can it be an interference of the read command over the write one? Or the other way around?
Thanks for the help.
I2C_M_IGNORE_NCK
in README.md, should be I2C_M_IGNORE_NAK
Hi, in my actual project I need to send a payload of 12 bytes using i2c. I have tried it, but only 4 bytes are sent in a single I2C message. Is there a maximum payload size of 4 bytes? If this is it, can this be changed?
Thank you for the help.
When I try to write to my sensor i am getting a segmentation fault. I have narrowed it down to tmp_buf is being set to basically -inf after going through i2c_iaddr_convert. Do you have any idea as to why that may be happening?
Thanks in advance for any help :)
Hi,
I am trying to compile C++ code based on the example code "i2c_without_internal_address.c"
However I keep getting erros when compiling such as:
undefined reference to `i2c_open'
undefined reference to `i2c_ioctl_write'
undefined reference to `i2c_close'
Is ther a proper way to compile perhaps? I'm using g++ my_code.cpp -o output
I would like to use pylibi2c
as a dependency on another project.
Does the author plan to publish it to pypi? If not, would it be ok if I forked and published it there?
I have noticed the library lets me compile the C code using a C++ compiler (hence the #ifdef __cplusplus extern "C" { #endif
blocks).
However I am getting errors when I compile the library, using g++ 7.5.0:
vendor/libi2c/src/i2c.c: In function ‘ssize_t i2c_ioctl_read(const I2CDevice*, unsigned int, void*, size_t)’:
vendor/libi2c/src/i2c.c:122:28: error: invalid conversion from ‘void*’ to ‘__u8* {aka unsigned char*}’ [-fpermissive]
ioctl_msg[1].buf = buf;
^~~
vendor/libi2c/src/i2c.c:135:28: error: invalid conversion from ‘void*’ to ‘__u8* {aka unsigned char*}’ [-fpermissive]
ioctl_msg[0].buf = buf;
^~~
vendor/libi2c/src/i2c.c: In function ‘ssize_t i2c_ioctl_write(const I2CDevice*, unsigned int, const void*, size_t)’:
vendor/libi2c/src/i2c.c:158:35: error: invalid conversion from ‘const void*’ to ‘const unsigned char*’ [-fpermissive]
const unsigned char *buffer = buf;
^~~
vendor/libi2c/src/i2c.c: In function ‘ssize_t i2c_write(const I2CDevice*, unsigned int, const void*, size_t)’:
vendor/libi2c/src/i2c.c:265:35: error: invalid conversion from ‘const void*’ to ‘const unsigned char*’ [-fpermissive]
const unsigned char *buffer = buf;
^~~
Makefile:28: recipe for target 'build/./vendor/libi2c/src/i2c.c.o' failed
The C++ compiler will not let you implicitly convert pointers.
This should be fixed by casting explicitly to (unsigned char*)
(source).
Is there a compiler setting I am missing? -fpermissive
is suggested but wouldn't that allow all implicit pointer conversions? All I changed is replacing $(CC)
in the Makefile with $(CXX)
for *.c
, which should work, because of your extern C
blocks.
Thank you in advance.
PS: Thanks for making this library
I know this may not be the place to ask this question, but I figured someone here might be able to help, so I have a python script:
#!/usr/bin/env python
import struct
import smbus
import sys
import time
def readCapacity(bus):
address = 0x36
read = bus.read_word_data(address, 4)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
capacity = swapped/256
return capacity
bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
while True:
print "******************"
print "Battery:%5i%%" % readCapacity(bus)
if readCapacity(bus) == 100:
print "Battery FULL"
if readCapacity(bus) < 20:
print "Battery LOW"
print "******************"
time.sleep(2)
And I have a NodeJS app, in this app I have this code:
try {
let socVoltage = fs.readFileSync('/sys/bus/i2c/drivers/ina3221x/6-0040/iio:device0/in_voltage0_input', 'utf8');
socVoltage = parseInt(socVoltage) / 1000.0;
socVoltage = `${socVoltage.toFixed(3)} V`;
sensors['Voltage'] = socVoltage;
} catch(err) {};
Is there a way I can get what the Python script is getting for capacity
into my NodeJS app in a similar way? I'm basically trying to not use python and just let my NodeJS app handle it.
Thanks in advance,
-b3ck
Hi, I am using libi2c to communicate between a Jetson TX2 and a Teensy 3.6.
The thing is that I'd like to send numbers (I send values to the teensy via i2c and the teensy does its things, then the teensy reads a sensor and sends the data to the Jetson).
However, I've been looking at the source of the code and I can't see a way of sending numerical values in a way that is not a char (each number would take 1 byte = 123 takes 3 bytes).
Is there a way to do so?
Thanks for the help.
I'm experiencing linker errors when trying to use both libi2c lib with libgpiod.
So, when I try to use, for example g++ source.cpp -o out -llibgpiodcxx -li2c
with both libs installed I'm getting errors like this:
undefined reference to `gpiod::chip::open(std::__cxx11::basic_string<char, std::char_traits
<char>, std::allocator<char> > const&)
Or same with any other function that use C++ structs or functions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.