How to connect to MCP2221 USB/I2C adapter

I wanted to play with some cheap Temp/Humidity sensors from Adafruit so I bought their AHT20 sensor and their MCP2221 based USB to I2C adapter.

After plugging it into the Rio and rebooting I can see that the kernel detects it, but I don’t see any reference to a complete /dev device path.

I tried installing the AHT20 node but it requires NodeJS >= 14 and the Rio as of the current firmware is on 12.x.

I then tried using the I2C contrib node for RPi but I’m guessing it connects directly to the I2C hardware and not through a USB interface since it didn’t find anything.

Any other ideas?

Ah, Linux driver fun and games!

In short, we only include the FTDI USB to Serial chip /dev/ driver for TTY devices.

So, not sure what options are here for you… I2C to serial converter and then use one of the FTDI genuine converters?
Or, (without looking into it) what Linux drivers are there for I2C? Could you build one from source and go that way?
We do intend to bump the version of NodeJS in an upcoming firmware update, but please don’t hold your breath for that, no solid ETA on that, don’t wan you turning blue!

1 Like

Well I think the MCP2221 already provides a serial interface. I was hoping I would see some kind of /dev/tty or /dev/ttyAMC0 or the likes in the system log, reference it in a Node Red node and it “just works” :slight_smile:

Here’s the Adafruit link with more details:

It doesn’t look like I should need an additional USB->Serial converter.

Looking here I may need to install some additional packages, I’ve “ordered” an SSH license for my Rio.

Thanks for the link. That micro is a USB device, not a USB to Serial converter. Its a USB to I2C ‘converter’ (its not really even that, its more of a ‘USB to many other devices including GPIO’ converter). So hence when you plug it in, Linux does not know what to do with it as it can not know what devices are plugged into the other end and how it should talk to them.

Your second link is getting closer to the mark in that you can write some code to talk to the I2C device you have connected to the adapter. Since you know what I2C devices are on the other end, you can tell the Linux kernel how to talk to them out the USB port.
A lot of customers are doing cool things with Python on EPIC. There are many threads on the forums here talking about some tweaks you may end up doing.
Keep in mind that shell fun and games does not carry through a firmware update, so keep good notes and please keep popping back here with how things go. Cool project for sure.

Just got my SSH license installed. Someone pointed this out to me:

How would I go about installing it?

Im sure I am misunderstanding, but what happen when you did as it suggested?

I didn’t know if there were any idiosyncrasies doing this on a Rio. Don’t I need to run this as the node-red user and not the ssh user I created?

This is not a Node-RED node, so you can run it as your shell user just fine.
The sample code he gives should like wise be run as your shell user.
Once you have temp and humidity data in your shell terminal, then you can think about how you are going to tie a bow around your data and what your end goal is.

The recommendation was to install the node package and try to use it in a function node, but you were right. Better to try manually first.

It didn’t work…

Worked for me.

What error did you get from the install?

My fault, should have been more specific. The install was fine, but running the example json code returned undefined undefined.

How did you run it?

We could really use some more help to help since we don’t have the hardware here.

I copied the example into a file in my home directory and ran it using the node command.

Did you program the board with the Python program it needs to read the I2C sensors you attached?

I was hoping the pure NodeJS module would work around the need for all the python stuff. I wasn’t able to do the pip install, I can’t remember the error, but it was likely due to the fact it doesn’t look like dev packages are available in the Opto 22 repositories (no libudev-dev package).

Sorry, what meant to say is that I think that micro is blank, it does not know what I2C sensors any customer is going to attach, so they just sell the board and you have to program the micro in Python with the library that match the sensors (in your case, humidity and temperature).
The Python is linked from the Adafruit page you first posted with.

Once that is done, then you can connect to the RIO and have a better chance of it returning the two values (at the moment Im suspecting its undefined undefined because, well, the sensors are undefined in the micro) and from there you can see about getting that into Node-RED on the RIO.

1 Like

I see what you mean, you REALLY have to have their circuitpython libraries to talk to the devices… Almost have it working on my Nano running Fedora 36.

I got it working on my Fedora Linux desktop computer. You really need to make sure the kernel driver isn’t loaded. I could rmmod it, get results for the sensor, but a short time later found the driver loaded again.

I’ve almost got it working on my Jetson Nano, but the adafruit library knows it’s running on a Jetson and is trying to access the native GPIO which I’m trying to work around.

That’s a pretty good update all things considered.
Perhaps now that the micro knows its sensors, its worth trying the small example you tried last time on the RIO and got the two undefined.

Thanks for keeping us all in the loop, its fun to follow along.