i2c Not working on Raspberry pi 1B

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
Abelynux
Posts: 4
Joined: Sat Sep 28, 2019 1:05 am
Been thanked: 2 times
Contact:

i2c Not working on Raspberry pi 1B

Post by Abelynux »

Hi everyone!

Very excited to be here! I just recently found about flowcode and, in the company I work we are very interested to adopt flowcode as our embedded IDE for test equipment development. We are specially interested on developing on the raspberry pi and arduino, so, I'm on the task to evaluate the software. I'm on an issue where I can't make the i2c work for raspberry (not yet started on arduino), I'm using a PCF8574 and I just want to blink an LED connected on one of its pins,
*I have tried several approaches, first the i2c_master, then the cal i2c and also the PCF8574 components without any success...
*I tried the i2cdetect to confirm operation of the i2c on the rpi, it detected the pcf on address 0x24, i was able to send the i2cset command and turn the led on and off (all these on the rpi terminal).
*I tried with both software and channel options (still don't understand what is the difference or intention of this mode), I also tried different speeds.

Hope someone can help!
Thanks and Best Regards!

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: i2c Not working on Raspberry pi 1B

Post by LeighM »

Hi,
Thanks for evaluating Flowcode!

The “software” mode directly manipulates any generic GPIO pins to implement the I2C protocol.
(Except the usual I2C pins if the Raspberry Pi hardware I2C is enabled!)
Using the Flowcode I2C “software mode” will work with all the Flowcode I2C derivative components.

The I2C component “hardware” mode only works with the installed Linux driver (e.g. /dev/i2c-1)
and this is only supported by the Flowcode I2C (CAL) component. See the “Creation” menu list.

The I2C (CAL) component has additional API to work with the Raspberry Pi transaction based drivers, namely:
Transaction_Intialise (pass the device address as a parameter)
Transaction_Read (pass a buffer to receive the transaction data)
Transaction_Write (pass a buffer that contains transaction data to send)

Hope that helps,
Leigh

Abelynux
Posts: 4
Joined: Sat Sep 28, 2019 1:05 am
Been thanked: 2 times
Contact:

Re: i2c Not working on Raspberry pi 1B

Post by Abelynux »

Hello! Thanks for your response Leigh!

I have been busy, I had a few minutes to play with the software today, I'm still struggling with the communication with i2c, now I understand the Channel option, so I tried using 2 different pair of GPIOs with the software mode, but still no luck, I did it using the 3 i2c components.

I will try to get more pictures with all the approaches I did or better the flowcode files, to begin with I attached the one with the PCF8574 component, also, we ordered a newer version of the RPi (is a 3 version but not sure what model A,B or whatever), we may wait to test with that.

Something that I'm stuck also, is when trying to fill a byte array variable, how I suppose to pass the value?, BYTE[], for the short reading I did, it seems like I have to convert to string, which sounds weird.

Best Regards!
Abel
Attachments
PCF8574_Component_software_mode.png
(115.4 KiB) Downloaded 1033 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: i2c Not working on Raspberry pi 1B

Post by LeighM »

Hi Abel,
Have you set the correct address for the PCF8574 ?
It is based on the wiring of the PCF8574 A0,1,2 pins, which are usually all tied low for one device, hence address 0.
Have you got pull-up resistors on the clock and data pins?
Strings and byte arrays are pretty much interchangeable in Flowcode, so if the component macro requests a string parameter then you can pass a byte array variable. Similarly you can use string variables to store a series of byte values.

Abelynux
Posts: 4
Joined: Sat Sep 28, 2019 1:05 am
Been thanked: 2 times
Contact:

Re: i2c Not working on Raspberry pi 1B

Post by Abelynux »

Hi Leigh!

Address is set correctly, but you pointed something, initially when I was playing with the "native" i2c channel, I didn't install pull ups due it supposes it already have them, so I just missed them when I tried with the software mode, I haven't tried but I will do shortly. I will keep you posted.

Thanks a lot!

Abelynux
Posts: 4
Joined: Sat Sep 28, 2019 1:05 am
Been thanked: 2 times
Contact:

Re: i2c Not working on Raspberry pi 1B

Post by Abelynux »

Hi Leigh!

I was able to make it work with the software mode for the PCF and i2c_master components, the pull ups did it, Thanks for pointing that!... I can't make the cal_i2c work in hardware mode yet. I will be busy for a few days, so I may not be able to continue until end of next week.

I still struggling with the byte array value assignation, this is required on the cal_i2c transaction_write parameters, I tried for example, 255,0,34,... but it throws me an error: syntax error, not sure what it is expecting. Attached a picture of the section where I need to fill the byte[] array.

Thanks so much for your help!
Abel
Attachments
Byte_Array.PNG
(2.93 KiB) Downloaded 996 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: i2c Not working on Raspberry pi 1B

Post by Benj »

Hello,

You need to pass the byte array via avariable, so create a byte variable as normal and at the end of the variable name add the square brackets and the number of items inside the array.

e.g. myVar[3]

You can then initialise the array using a calculation icon in your program.

myVar[0] = 255
myVar[1] = 0
myVar[2] = 34

Then simply pass MyVar as the parameter.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: i2c Not working on Raspberry pi 1B

Post by LeighM »

And pass Length parameter as 3 in that example

Post Reply