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): [1] 

|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.
 

Links:
------
[1] https://learn.adafruit.com/introducing-trinket/introduction)

Reply via email to