Hi Steven.

I added I2C support
<https://github.com/pharo-iot/PharoThings/releases/tag/v0.2.1> to
PharoThings and WiringPi.

Now you can ask the board instance for I2C connection:

i2cConnection := board connectToI2CDevice: 4.


And then read/write data using wiringpi functions like:

i2cConnection readData.
i2cConnection read8BitsAt: 16r32 "register".

i2cConnection writeData: 16rAB.
i2cConnection write8BitsAt: 16r32 "register" data: 16rA5.


Also I added I2CDevice as superclass for simple i2c devices. There is
example of accelerometer ADXL345. Look for details.


Best regards,
Denis


2017-12-19 23:20 GMT+01:00 Steven Costiou <steven.cost...@kloum.io>:

> hi,
>
> i've tried i2c and added ffi calls in WiringPiLibrary.
>
> *wiringPiI2cSetup: devId*
>
>     ^self ffiCall: #(int wiringPiI2CSetup (int devId) )
>
> *readI2C: fd*
>
>     ^self ffiCall: #(int wiringPiI2CRead (int fd))
>
> Then the following script is able to read a byte from a connected device
> (i tried with a trinket https://learn.adafruit.com/introducing-trinket/
> introduction):
> <https://learn.adafruit.com/introducing-trinket/introduction)>
>
> |lib addr val|
>
> lib := WiringPiLibrary uniqueInstance.
>
> addr := self wiringPiSetupI2C: 4. *“Setup the i2c to the 0x04 address”*
> val := self readI2C: addr. *“Read a byte from the i2c address”*
>
> val inspect
>
> So connecting an Arduino-like device to the raspberry that is configured
> as an i2c slave, Pharo can ask for analog values. I will try tomorrow with
> analog sensors, I will share if i manage to build nice examples.
>
> Seems to be even easier using a special chip: https://learn.adafruit.com/
> reading-a-analog-in-and-controlling-audio-volume-with-
> the-raspberry-pi?view=all
>
> but it uses more pins on the board.
>
> Steven.
>
>
>
> Le 2017-12-17 19:48, Denis Kudriashov a écrit :
>
> Hi Steven
>
> 2017-12-17 12:40 GMT+01:00 Steven Costiou <steven.cost...@kloum.io>:
>
>> Hi,
>>
>> For what i know, raspberry pi boards cannot read analog sensors (which
>> are the most interesting imo), except by connecting to some kind of bridges
>> or to Arduino boards.
>>
>> In the PharoTHings code i see that there are Arduino classes, and also it
>> is based on wiringpi and wiringpi provides support for i2c which is needed
>> to connect to an Arduino and perform analog reads.
>>
>> I'm exploring the wiringpi doc to see if there is an example for that,
>> but in the meantime, would someone already have an example of analog reads
>> with PharoThings, with working code (even simple) ?
>>
> It is in my todo. I need to build example with temperature sensor. I will
> continue work on it next year.
> Now feel free to contribute to the project.
>
> About Arduino: it is not finished. Problem that I use Mac but serial port
> is not working there (it is required for Firmata)
>
>>
>>
>> Steven.
>>
>

Reply via email to