Issues with Teensy 3.2 I2C

Status
Not open for further replies.

SzymonZieba

New member
Hi all,

I have been working with the Teensy 3.2 for around a week now and have come into a rather unusual problem.

My Setup is as follows:
  • Teensy 3.2 with Vin/Vusb pads cut
  • Grove Multichannel Gas Sensor connected to pins 18 & 19 as appropriate
  • LiPo Battery
  • 3.3V Buck Boost Regulator
  • 4.7kohm Resistors for pull-up

There are some additional items connected to the Teensy, however half are turned off by the time the program attempts to read the Grove, and the other half are analog sensors drawing very little current.

Key part of the code is here:
void readGrove() {
//Declare Variable
fTob c;

int timeout = 0;

delay(100);

c.f = gas.measure_CO();
//while(c.f < 0) {
//timeout++;
c.f = gas.measure_CO();
//if (timeout > 20) {
//break;
//}
//}
//Serial.println(c.f);

message[6] = c.bin[3];
message[7] = c.bin[2];

delay(100);

c.f = gas.measure_NO2();

uint8_t t = c.f*100;

message[8] = t;

gas.powerOff();
}
gas.powerOn() and gas.begin are used in setup and loop functions.

When I have a usb plugged into the Teensy's usb port, the I2C communication with the Gas Sensor works fine, having no issues getting a response. However, when I disconnect the usb, the I2C stops working. Watching on an oscilloscope we have seen two different events, one where a message was sent along the SDA line, but no response was made and one where no message was sent period. We have no idea what is going on. We are using the Multichannel Gas Sensor library practically as is, commenting out any Serial prints.

Does anyone have a suggestion on what may be going wrong?
 
I suggest it is your power supply at fault. Try a nice linear regulated bench supply in place of your battery and buck boost converter.
 
hi,

commenting out any Serial prints

did you also remove code with something like waiting for serial events, data comming in, serial port available etc.
e.g.:
Code:
//wait serial port to open/connect
while(!Serial){
//nothing;
}
...

the mcu may get stuck if somewhere in your code waiting for serial events.
 
Might help to see actual wiring and the like, plus the actual code.

Things like: you say using 3.3V Buck Boost Regulator, am I assuming your lipo is a 1S? How is it connected to T3.2? At the 3.3v pin? How are the PU resistors connected? To the 3.3v pin as well or to VIN which might not have anything...

Code as mentioned by Welocs maybe code has something like while (!serial...)

Is it this sensor: https://www.amazon.com/Seeedstudio-...0338&sr=8-2-spons&keywords=grove+sensor&psc=1
If so it says can use up to Max Power: 150mW

So as suggested, you might want to try a different power supply and see if the problem is still there (then probably code) or if that solves it
 
Hi,

Unfortunately I am limited to what I can show of wiring and code as I am currently unsure of what would fall under my confidentiality agreement.
I can say however that the LiPo is a single cell battery. It may be worth mentioning that the battery is connected through a LiPo Battery Babysitter (from Sparkfun) where the power is then pulled out of. The output power of the babysitter is then connected to the Vin port of the T3.2 (I had previously tested connecting to the 3.3V pin from the regulator but found little change in power draw). The pull up resistors are connected to the 3.3V rail on the bread board.

I should note that I don't have any cases of the line while(!Serial) in the code (the closest is while(!Serial2) as I was having some issues with one of the Serial devices connected). In addition, I find it unlikely to be a power supply issue. I tested the connections using a multi-meter and a oscilloscope and there seems to be no difference in voltage between having a usb plugged in and not having it plugged in (which is expected as the usb should not be currently able to power anything). Also, the multi-channel sensor (the one KurtE found is the exact one I have) was initially connected to a separate 5V rail from before these issues started appearing, before you ask, the 5V rail is shutdown before trying to communicate with the multi-channel sensor. Unfortunately I don't have access to a bench top power supply at this time, may need to look into purchasing one.
 
Just wanted to add, we have now tested using a logic analyser, and found that there is one more case I didn't mention previously, where the communication gets stuck in a loop. The message (confirmed with the logic analyser) is correct without the usb but then either no return message is made or the T3.2 gets stuck and doesn't translate the incoming message until the usb port is plugged in.
 
Last edited:
>>> doesn't translate the incoming message until the usb port is plugged in.

I am interpreting that to mean the unit is stalled and you do nothing else other than plug in the usb and it starts working again.

I am thinking the usb is stalled with a buffers full condition or something like that. As a suggestion, try compiling with USB type as NO USB. Other forum members with more experience than me, please chime in.
 
Thanks rcarr,

That actually worked, I set the clock speed to 2MHz. It just works like a charm now (one other device is having some issues but it is relatively minor as it is just measuring temperature). I wonder if it was just processing faster than it read the messages and was getting confused?

Thanks for all the help :)
 
I connected Multichannel Gas sensor (https://www.seeedstudio.com/Grove-Multichannel-Gas-Sensor-p-2502.html) to Teensy 3.2
GND-GND
VCC-VCC (5V)
SCL- 19 pin
SDA - 18 pin

But can't read data.
I receive (for all gas) "The concentration ... is invalid ppm"
Code:
/*
    This is a demo to test gas library
    This code is running on Xadow-mainboard, and the I2C slave is Xadow-gas
    There is a ATmega168PA on Xadow-gas, it get sensors output and feed back to master.
    the data is raw ADC value, algorithm should be realized on master.

    please feel free to write email to me if there is any question

    Jacky Zhang, Embedded Software Engineer
    qi.zhang@seeed.cc
    17,mar,2015
*/

#include <Wire.h>
#include "MutichannelGasSensor.h"

void setup()
{
    Serial.begin(115200);  // start serial for output
    Serial.println("power on!");
    gas.begin(0x04);//the default I2C address of the slave is 0x04
    gas.powerOn();
    Serial.print("Firmware Version = ");
    Serial.println(gas.getVersion());
}

void loop()
{
    float c;

    c = gas.measure_NH3();
    Serial.print("The concentration of NH3 is ");
    if(c>=0) Serial.print(c);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c = gas.measure_CO();
    Serial.print("The concentration of CO is ");
    if(c>=0) Serial.print(c);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c = gas.measure_NO2();
    Serial.print("The concentration of NO2 is ");
    if(c>=0) Serial.print(c);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c = gas.measure_C3H8();
    Serial.print("The concentration of C3H8 is ");
    if(c>=0) Serial.print(c);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c = gas.measure_C4H10();
    Serial.print("The concentration of C4H10 is ");
    if(c>=0) Serial.print(c);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c = gas.measure_CH4();
    Serial.print("The concentration of CH4 is ");
    if(c>=0) Serial.print(c);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c = gas.measure_H2();
    Serial.print("The concentration of H2 is ");
    if(c>=0) Serial.print(c);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c = gas.measure_C2H5OH();
    Serial.print("The concentration of C2H5OH is ");
    if(c>=0) Serial.print(c);
    else Serial.print("invalid");
    Serial.println(" ppm");

    delay(1000);
    Serial.println("...");
}
 
I added pullup resistors (10 kOhm) bitwin VCC and SDA but can't read data.
I use SCL- 19 pin, SDA - 18 pin for connecting BME280 and Multichannel Gas sensor simultaneously.
Maybe is it the problem?
 
Teensy 3.2
On sensor
VCC+GND - 4,85 V
VCC+SCK - 4,75-4,85 V
VCC+MOSI - 0,13 (without 10KOhm) and 1.65 V with 10KOhm
VCC+MISO - 0,13-0,15 (without 10KOhm) and 1.65 V with 10KOhm
VCC+NRST - 0
On sensor board input-output
VCC+GND - 4,85 V
VCC+SDA - 3,95-4,05
VCC+SCL - 2,77-2,85

Arduino UNO
VCC+GND - 5,09 V
VCC+SCK - 5,09 V
VCC+MOSI - 0,09
VCC+MISO - 0,13
VCC+NRST - 0
On sensor board input-output
VCC+GND - 5,09 V
VCC+SDA - 0,05-0,9
VCC+SCL - 0,05-0,75
 
Last edited:
for 5 volt devices i had some issues but i was on a Teensy 3.5. the I2C ‘network’ wasn’t stable (i use only i2c_t3)

So, what I did and it’s been working fine since with 5v devices is I used a level shifter for the i2c bus
never had issue since

without the level shifter some of my 5v devices had issues not only working, but being detected on the bus
 
Spec page for the sensor says 3.1-5v so you should be okay.

You need 4.7K pullups on both SDA and SCK lines, not a single 10K pullup on SDA. Best to put the pullups to 3.3v.

Run the scanner sketch "File->Examples->Wire->Scanner". What does it say? Does it find the sensor? If not, you have a connection problem meaning either the sensor is miss connected, pullups aren't working, or as tonton81 suggests it won't run w/ Teensy's 3.3 I2C voltages and you'll need a level shifter.
 
thats the level shifter i use, dgranger, without the level shifter, the scan wouldnt find *all* devices in my case... that was one of the issues i remember too :)
 
Sorry guys I didn't use the level shifter never. How connect Teensy and sensor to it and what kind of level shifter are you use?
 
is very simple, the low side connects to teensy, low side rails is 3.3v

the high side is where your 5v devices attach to, it has 5v on its rails

this allows both teensy and device talk to each other at their respective voltage levels
 
Usually level shifters are not needed with Teensy 3.2. Usually all you need is the pullup resistors. 10K or 4.7K are fine.

Before you go to all that (probably unnecessary) trouble, please let us try to better help you by posting photos to show how you've actually connected the wires and all parts. Often these sorts of problems turn out to be a simple misunderstanding. We might be able to see the problem if you show us photos.

I'd also like to echo the dgranger's advise from msg #16. Click File > Examples > Wire > Scanner and run it on your board. It's possible the hardware is ok, but something is wrong with the software side. If the hardware is connected and responding to I2C, this scanner will show a response at the chip's address.
 
Click File > Examples > Wire > Scanner

Result:
Scanning...
Device found at address 0x04 (unknown chip)
Device found at address 0x76 (MS5607,MS5611,MS5637,BMP280)
done
 
Just guessing ... but to see if you can get Firmware version right on Teensy, try editing the library. In get_addr_dta() change Wire.endTransmission(); to Wire.endTransmission(false);

There are some int's in the library (int's on UNO are 16 bits, but 32-bits on Teensy), but I'm not sure if that is an issue in this case.

Speed is the other potential problem (teensy is 6 times faster). Maybe add delay(1) after endTransmission() ?

Maybe remove other I2C devices ...
 
Last edited:
Update: I don't have the breakout, but since the I2C logic on the breakout is controlled by an ATmega168PA, I downloaded the firmware onto a UNO and added the library to IDE
https://github.com/Seeed-Studio/Mutichannel_Gas_Sensor

I ran this sketch on T3.2 with common ground and SDA and SCL connected to UNO.
Code:
// Get firmware version of Grove Multichannel Gas Sensor
#include <Wire.h>
#include "MutichannelGasSensor.h"

#define SENSOR_ADDR     0X04        // default to 0x04

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  delay(2000);
  gas.begin(SENSOR_ADDR);
}

void loop()
{
  unsigned char version = gas.getVersion();
  Serial.print("Version = ");
  Serial.println(version);
  delay(2000);
}
It correctly printed Version = 2
So T3.2 can talk I2C to the firmware on UNO.

With meter, I confirmed that SCL and SDA were pulled HIGH to 5v (by the UNO Wire lib and schematic shows 10K pullups on SDA and SCL). No level-shifters or additional pullups were used.

I also ran several of the examples from library (RawData and ReadSensorValue_Grove), and they seemed to work. Of course, the UNO is just returning random values from the analogRead's in the firmware.
Code:
The concentration of NH3 is 65.47 ppm
The concentration of CO is 329.39 ppm
The concentration of NO2 is 0.27 ppm
The concentration of C3H8 is 557750.81 ppm
The concentration of C4H10 is 137766.22 ppm
The concentration of CH4 is ovf ppm
The concentration of H2 is 533.39 ppm
The concentration of C2H5OH is 477.77 ppm


So in principle, it works for me, though UNO is running at 16MHz and schematic shows mega168 has 8MHz crystal.

http://wiki.seeedstudio.com/Grove-Multichannel_Gas_Sensor/

Update: I also tested with 3.3v 8MHz pro mini (328p). Response was sluggish/intermittent, even with T3.2 @24mhz. I got ReadSensorValue_Grove example to run with T3.2@96mhz by adding delay(1); before each Wire.requestFrom() in the library and at the end of the powerOn() function. No pullups other than 328p's internal pullups enabled by Wire lib.
Code:
The concentration of NH3 is 0.68 ppm
The concentration of CO is 4.39 ppm
The concentration of NO2 is 0.15 ppm
The concentration of C3H8 is 570.16 ppm
The concentration of C4H10 is 398.11 ppm
The concentration of CH4 is 269.07 ppm
The concentration of H2 is 0.73 ppm
The concentration of C2H5OH is 1.62 ppm
 
Last edited:
Status
Not open for further replies.
Back
Top