Anyone used the IC2 protocol before?

Does anybody know if the IC2 protocol can be used in a Xojo Raspberry Pi project?

there are two serial (UART) channels on my board. But I need more.
My solution was to use other pins to set or unset enable-pins on some shields, so I can use a serial connection for multiple peripherals.

But some of my shields support the I2C protocol, where I could use a lot more devices on 1 channel.

There is a link in the Xojo documentation. So, there must be some support for it. But does anyone have any experience with this?

I did that.

1 Like

In my old guides then I did such once or twice, at least with the Analog to Digital project I know it was used.

Can find the old guides here:

All my old guides were WiringPI guides. Even if the original creator of it no longer supports it then I would still use Wiring PI my self, by using 3rd party fork. Reason is that Wiring PI also works on most of the 3rd part boards.,

Some links to Wiring PI libraries:

2 Likes

I am in the process of a Rasp Pi5 → PICO WH project that utilizes I2C. I have several requests out on TouchScreen and I2C on this forum as I was seeking knowledge on how to go forward.

What I can tell you is that as others have suggested to me an understanding of I2C and how it relates to the PIGPIO library has made a difference.

This is not as easy an undertaking in what I will call simple desktop applications using XOJO. That is IMHO mainly because this is a smaller audience. However once you get through the learning curve there is a lot you can do.

For instance: I needed to rewrite UI controls as I am not using a keyboard or mouse. I received some excellent help in this area on this forum. But none of that was I2C related. So I worked on what I could solve at that time.

Lastly: The I2C communication needs I have was to create my own token protocol that I would use STRINGS to send information back and forth. This is compounded by my choice to use C as the language on the PICO. That means strings or char or char* (string) cannot be placed in a Select statement but a nested else - else if… Also I am using the RaspPi5 as Controller and PICOs as Peripherals. There is not a lot of information out there on this however there is enough that will enable you to get this accomplished.

Eugene Dakin has a book you can get on XDEV Jan 2021 Edition (3.3). A wish of mine is that he revisits that book and updates to the latest RASPIOS and XOJO. Then also to include how to implement your own communications token passing architecture. Despite that the book is worth purchasing as it helps as well as the “Advanced Raspberry Pi” book by Warren Gay - APRESS.

I implemented a string token protocol because that forces me to upfront deal with multi byte transmissions which IMHO enables an expanded communications capability that is human like (readable) in its implementation.

So I can tell you it is more than possible to implement I2C in the Rasp Pi. I have now completed a significant UI Control development as well as passing I2C communications that control endpoint control devices on the PICO with ACKs being sent back. What looked hopeless in the beginning is now looking very promising. Of course I would like XOJO to improve the RASP implementation and there are several suggestions you can find on the wish list. I would like to see sooner rather than later XOJO pick them up.

1 Like

Hello @Carl_Fitzsimmons,

Glad to hear you enjoyed the Raspberry Pi book that included I2C communication. You are correct, the book can be updated and I have written many articles with the latest - and hopefully last, Xojo-wrapper of the C-library lgpio (GitHub - eugenedakin/lgpio-GPIO: Wrapper uses the new C-language gpiochip functions for the Raspberry Pi). I like the two-wire protocol and have many video teasers on my youtube channel with Xojo and Raspberry Pi Electronics (https://www.youtube.com/@eugenedakin).

The latest lgpio library is faster and more compatible than previous libraries. What I find is that each library (PiGPIO, Wiring Pi, Adafruit, and more) are available and are typically deprecated. This brings me to a fork-in-the-road with Raspberry Pi and Xojo with GPIO’s: I hope that lgpio is the last version (at least for a long-while) and also hope that API2 remains the latest version for Xojo.

Another issue that I continuously see and troubleshoot is with electronics themselves. There are chips that have poor quality and I am continuously swapping parts from trusted suppliers. I am considering releasing my own line of components, as quality in the electronics world seems to be a rare commodity.

For a list of articles using I2C with Xojo API2, feel free to view my LINKEDIN account in the PROJECTS section for more I2C articles: https://www.linkedin.com/in/eugenedakin/details/projects/

As a side note, I am curious to see performance increases with multi-core threads with Xojo.

I am chatting with a few potential investors to see what options should be investigated, and as an example: 1) launch Xojo electronics line, 2) Xojo PLC, 3) new Xojo library, 4) write another Pi Electronics book with the latest library, etc.

2 Likes

Well this comment may not help as I would like to see 1-4. I am what I would refer to as a bit twiddler in that I figure out how to control bits on micros using various communication methods (IP, WiFi, BLE, RS…) to control end effectors (solenoids, FETs etc). I also develop data conversion aspects that support telecommunications needs. Utilized primarily in Cisco UC where I convert and prepare phone-voicemail setup. I found Anthonys Web Graffiti Suite quite helpful in that effort.

For me I2C and Bluetooth are important with respect to RaspPi(5) and PCIO integration. I will implement BLE where existing wiring does not exist. Both the PICO and RaspPi can communicate up tp 100m (depends on clear site - metal etc.) which is an important factor. As a result I see this as a powerful #3 in your asks.

The LinkedIn link fails

Thanks for the links to the improved Pi GPIO libs. After following the steps the following deprecation messages were posted. (This supports
carlfitzsimmons@raspberrypi5:~/lg $ sudo make install
install -m 0644 lgpio.h /usr/local/include
install -m 0644 rgpio.h /usr/local/include
install -m 0755 liblgpio.so.1 /usr/local/lib
install -m 0755 librgpio.so.1 /usr/local/lib
install -m 0755 rgpiod /usr/local/bin
install -m 0755 rgs /usr/local/bin
install -m 0644 rgpiod.1 /usr/local/man/man1
install -m 0644 rgs.1 /usr/local/man/man1
install -m 0644 lgpio.3 /usr/local/man/man3
install -m 0644 rgpio.3 /usr/local/man/man3
ldconfig
/usr/bin/python3
/usr/lib/python3/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
/usr/lib/python3/dist-packages/setuptools/command/easy_install.py:146: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
/usr/bin/python3

The ever changing world of software. In your opinion how best should I proceed?

Do you have examples on I2C setup, writing, and reading?

1 Like

Hello @Carl_Fitzsimmons,

Thanks for the feedback, and I’ll see what I can do. No promises though.

Hmm, thats weird. I’ll check on the link and see if there is another way of sharing it.

Here are the instructions to install the latest lgpio library on the Raspberry Pi (includes Raspberry Pi 5), and the link is at my Github page: GitHub - eugenedakin/lgpio-GPIO: Wrapper uses the new C-language gpiochip functions for the Raspberry Pi. Let me know if these instructions work on the Raspberry Pi.

I have some I2C examples. This example uses I2C with the MPL3115A2 Barometric/Altitude/Temperature sensor:
LibGPIODI2CRev3.zip (17.9 KB)

Here is an example using I2C with the MPU6050 Sensor which has Gyroscope/Accelerometer/Temperature measurements:
LibGPIODI2CRev17.zip (34.8 KB)

An I2C example with the ADS1115 that converts Analogue voltage to Digital Measurements:
LibGPIODI2CADS-Rev18.zip (8.7 KB)

My suggestion is to use the latest lgpio library, as it has been getting updates, and the other libraries (WiringPi, PiGPIO, etc) are deprecated. Some of the older libraries work on the Raspberry Pi 5, while some older GPIO libraries only work on Raspberry Pi 4’s and older.

Let me know if the lgpio library installs on Raspberry Pi 5 with no issues.

Here is an update.

After some extensive efforts I am ending this I2C implementation. Basically what I read prior to starting is that I2C is supported and PICO can be a Peripheral/Slave. What I found using VSC C code using an ISR was inconsistent communications when I made the PICO a Peripheral/Slave and the RaspPi5 a Controller/Master.

Without a logic analyzer I worked through several iterations of C code to debug what the ISR was receiving. In the end it appears that the STOP conditions were not consistently occurring leaving the PICO in the wrong state. This could be part C library part XOJO and I am not certain which it is. I know for certain that the Address portion works great. The part that fails is sending a command in the multi byte token protocol (TP) I am using. The PICO never sees the STOP when writing to it using WriteBlock to send the TP request to the PICO. The PICO receives the entire message but never receives STOP. T.hat is what leaves the PICO in the wrong state.

I made several circuit changes to improve and reduce the possibility of problems. I can say this that the circuit on the RaspPi5 and PICO configured as Controller/Master works when either is connected to a Peripheral/Slave such as a temperature board.

At this time I need to complete the project so I am ending the I2C effort. I am switching to BLE which may also be another problem in terms of XOJO but we shall see. After looking at the full scope of this project it makes sense to move to BLE anyway.

there are some very cheap logic analyzers that are more then enough to debug i2c
like
https://www.aliexpress.com/item/1005005698409712.html
or
https://www.aliexpress.com/item/1005006102804065.html
use it with the sigrok pulseview free app
https://sigrok.org/wiki/Downloads