Giter Site home page Giter Site logo

libi2c's People

Contributors

amaork avatar itsnayabsd avatar jhh avatar mdegans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libi2c's Issues

Build failed: redefinition

redefinition of ‘union i2c_smbus_data’
redefinition of ‘struct i2c_msg’

FIXED by comment #include <linux/i2c.h> in src/i2c.h

reading and writing in the same script

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.

Maximum bytes per message

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.

Segmentation fault when trying to write to sensor

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 :)

Undefined References

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

Publish to pypi?

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?

Compilation error when using c++ compiler: invalid conversion from `void*` to `__u8* {aka unsigned char*}`

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

Python into NodeJS?

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

Sending integers/floats instead of chars

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.

Undefined reference to any C++11 class or function when linked both with libgpiod

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.