Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 4 as a USB-I2C gateway for OpenWrt

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    2

    Teensy 4 as a USB-I2C gateway for OpenWrt

    Hei,

    I am trying to design a sensor network infrastructure for environmental noise and air quality measurements. There is a brilliant project with similar focus which is doing noise measurements with a Teensy 4.0 and providing data through a software I2C slave. As a controller platform I am considering Raspbian and OpenWrt. While the Rapsberry platform has the advantage of offering a lot of headroom for applications like ADS-B flight transponder data collection, the OpenWrt on a small travel router with USB connector is easier to set up for technically not so interested user. Ideally the transfer protocol could be used in both approaches.

    How to transfer measurement data from the Teensy to the controller? While I2C works fine for the Raspberry it does not generally for the OpenWrt hardware. Furthermore it requires additionally wiring. The easiest way from a hardware side of view would be to use the USB interface. The Teensy would have just a single micro USB connector for power supply and data transfer to the host. Now, OpenWrt does not have a wide USB device support. There are no drivers packages to make the Teensy with its vendor ID 0x16c0 known to the system. Thus it is tempting to make use of a USB device/solution that is supported. Three categories come to my mind:

    • Plain serial
    • Modbus
    • I2C gateway

    Developing a protocol for plain serial sounds for me like reinventing a wheel. Modbus is a bit outdated for new projects and has a very restricted set of data types. Then I2C. There is an excellent "tiny" project for a USB-I2C gateway using an Atmel Tiny MCU. What is needed emulating this approach?

    • Modification of usb_desc.h (and usb_desc.c?) using the VID and PID of the I2C-Tiny-USB project
    • Writing a USB gateway class


    Does this approach make sense or are there much better solutions for getting a set of I2C sensors connected to an USB consumer?

    Greetings,
    buv

  2. #2
    Senior Member pictographer's Avatar
    Join Date
    May 2013
    Location
    San Jose, CA
    Posts
    701
    I've done something like this with plain serial. It's a little wonky if the serial port also has all the console messages. You can disable the console messages, but then debugging the system gets harder. What I do instead is use USB serial.

    Now, OpenWrt does not have a wide USB device support. There are no drivers packages to make the Teensy with its vendor ID 0x16c0 known to the system.
    I suppose this depends on what you mean by "wide USB device support". I see plenty of USB entries when I type "make menuconfig" for OpenWrt. Right now on my desk, I have a GL-iNet Mango GL-MT300N-V2 Mini Router. It came with OpenWrt pre-installed and with some vendor UX stuff to make it more friendly. I have it plugged into a Teensy LC via USB-A on the Mango and USB micro on the Teensy. The Teensy is recognized as a USB serial device. You can read and write text to /dev/ttyACM0 to interact with the Teensy. Or at least you can with OpenWrt 19.07.7 and the right set of packages installed.

    I can even reconfigure the Teensy over the air. Until recently, I hadn't been successful at porting teensy_loader_cli to Mips-based OpenWrt hosts. However, now it builds and runs. The USB serial support on OpenWrt works okay, but not perfectly. I can flash new firmware to the Teensy without pushing the button, but I need to run usbreset before and need to get the Teensy to call _reboot_Teensyduino_(). Sometimes, I need to reboot the router beforehand. Not ideal, but a big improvement in my case.

    I expect a more deterministic scheme would be to use a GPIO from the router to control the program pin on the Teensy, but I haven't tried it. It might also be possible to do something clever by power cycling the USB port and having some little timer circuit hold the Teensy in program mode until the router has a chance to run teensy_loader_cli.

  3. #3
    Junior Member
    Join Date
    Feb 2021
    Posts
    2
    Thank you for your answer. What a coincidence: I am using the GL.iNet GL-MT300N-V2 as well. :-)

    My problem was that I did not know that I had to install the appropriate driver in order to be able to talk to the Teensy. What was missing was the kmod-usb-acm package. Now Teensy is recognized and I can do my communication easily using serial.

    Greetings,
    buv

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •