I2C Problems - Autonomo

Hi,

Questions about I2C and Autonomo. We are trying to get two different Melexis sensors working but are having troubles getting the I2C working with the autonomo. We have it working on different other Arduino’s and have solved the 32bit problem already. We only use the wire.h library, but device stays sending FF FF back (error).

Any tips on debugging?

Thanks!

I have this working on an AUTONOMO with a ublox-8 gps without any problems … are you using the most recent sodaq boards manager? can you share your code ? I use below to scan the I2C on startup …

BTW : 0xff is returned when there is no data to read …

void scani2c(TwoWire& WireX) {
int nDevices = 0;
uint32_t now = millis();
for (int address = 1; address < 127 && (millis() - now) < 5000; address++) {
WireX.beginTransmission(address);
int error = WireX.endTransmission();
if (error == 0) {
SerialUSB.print(“I2C device found at address 0x”);
if (address < 16)
SerialUSB.print(“0”);
SerialUSB.print(address, HEX);
SerialUSB.println(" !");
nDevices++;
}
else if (error == 4) {
SerialUSB.print(“Unknow error at address 0x”);
if (address < 16)
SerialUSB.print(“0”);
SerialUSB.println(address, HEX);
}
}
if (nDevices == 0)
SerialUSB.println(“No I2C devices found\n”);
else
SerialUSB.println(“done\n”);

}

BTW. A tip to format the code on this forum (in case you didn’t know). Start a line with at least 4 spaces.
It then looks like this.

void scani2c(TwoWire& WireX) {
    int nDevices = 0;
    uint32_t now = millis();
    for (int address = 1; address < 127 && (millis() - now) < 5000; address++) {
        WireX.beginTransmission(address);
        int error = WireX.endTransmission();
        if (error == 0) {
            SerialUSB.print("I2C device found at address 0x");
            if (address < 16)
                SerialUSB.print("0");
            SerialUSB.print(address, HEX);
            SerialUSB.println("  !");
            nDevices++;
        }
        else if (error == 4) {
            SerialUSB.print("Unknow error at address 0x");
            if (address < 16)
                SerialUSB.print("0");
            SerialUSB.println(address, HEX);
        }
    }
    if (nDevices == 0)
        SerialUSB.println("No I2C devices found\n");
    else
        SerialUSB.println("done\n");
}

The Autonomo doesn’t have pullup resistors. Your sensor need to have these. The gps module has them.
So maybe you need to add them to your custom I2C sensor.

Not sure what happened with the formatting, I copied it from my eclipse environment …

I think the SAMD has Internal pull-up or pull-down …

We have other I2C sensors working without problems. Still no luck with the Melexis tough. The code involved is the normal MLX90614 Library by Adafruit.

/*************************************************** 
  This is a library example for the MLX90614 Temp Sensor

  Designed specifically to work with the MLX90614 sensors in the
  adafruit shop
  ----> https://www.adafruit.com/products/1748
  ----> https://www.adafruit.com/products/1749

  These sensors use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);

  Serial.println("Adafruit MLX90614 test");  

  mlx.begin();  
}

void loop() {
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

  Serial.println();
  delay(500);
}

This works fine on any other Arduino board we have.

What we have tried so far:

  • Different pull-up resistors
  • Different clock speeds of the I2C bus
  • Adding delays in the code
  • running the scanner gave:

Scanning…
I2C device found at address 0x5A !
done

  • Looking at the waveform with a scope/logic analyzer. Here I seem some more nasty waveforms then on other arduino’s:

We ordered a Arduino m0 pro to verify if it actually works on the m0 chip.

I could only post one image at a time. Here is the next one
Arduino pro mini 3.3volt

And a zoom out on the interface to be clear what we see.

uint16_t Adafruit_MLX90614::read16(uint8_t a) {
  uint16_t ret;

  Wire.beginTransmission(_addr); // start transmission to device 
  Wire.write(a); // sends register address to read from
  Wire.endTransmission(false); // end transmission
  
  Wire.requestFrom(_addr, (uint8_t)3);// send data n-bytes read
  ret = Wire.read(); // receive DATA
  ret |= Wire.read() << 8; // receive DATA

  uint8_t pec = Wire.read();

  return ret;
}

For this bit of code to work you have to use the most recent board version for the autonomo, Wire.endTransmission(false); was not supported correctly before (issue in the arduino wire library, you can check your wire source to see if this flag actually does anything) the result can be that it returns 0xff (no data available) I’m using boards 1.6.7 in which this code works fine (at least something similair I use for an uBlox)

thanks for your reply! I am working together with FRVisser on this I2C problem.

Just upgrade to boards 1.6.7 but still same result/problem all 0xFF:


upgrade steps:

Just checked all the version: I had version of SODAQ 1.6.5 because I used for:
Additional board manager:
http://downloads.sodaq.net/package_sodaq_index.json

changed to:
http://downloads.sodaq.net/test/package_sodaq_index.json
(see extra test dir.)

so now on 1.6.7 SODAQ boards.
other version are:
arduino 1.6.8
wire 1.0.0

just checked the Wire.cpp
and found the:
169 uint8_t TwoWire::endTransmission(uint8_t sendStop)

so that looks okay.

So still no luck, which board should we select, just “Sodaq Autonomo”?

Thanks!
Jasper

Look for below in Wire.endTransmission(false) in older version this bool is not checked … you should indeed use Sodaq Autonomo. The addessing of the register should be followed immediately by a read and hence there should be no stop, but a continued start instead. Took me a while to figure that out for the uBlox which does the same to read number of available bytes.

if (stopBit)
{
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);
}

thanks! looks like I have the wrong wire.cpp / wire.h

Arduino.app/Contents/Java/hardware/arduino/avr/libraries/Wire/Wire.cpp

with the code:
int8_t TwoWire::endTransmission(uint8_t sendStop)
{
// transmit buffer (blocking)
int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1, sendStop);
// reset tx buffer iterator vars
txBufferIndex = 0;
txBufferLength = 0;
// indicate that we are done transmitting
transmitting = 0;
return ret;
}

I think you are talking about something like the samd code:

Looks like a problem in the arduino library/boards setup, any idea what it could be?
(I even downgrade arduino to 1.6.7, and install SODAQ boards autonomo again but did not matter)

Thanks,
Jasper

Hold on.
I see arduino/avr/libraries/ with “avr” in there.
Are you sure you’re looking at the right thing?

yes not good, but its the only wire.cpp I have on my laptop :confused:
Do you have an idea where I should look?

Thanks!

There should be a Wire.cpp at

~/.arduino15/packages/SODAQ/hardware/samd/1.6.7/libraries/Wire/Wire.cp

On a Mac it’s probably in ~/Library/…rduino15/ (in your HOME directory somewhere.
If you enable verbose build in Arduino you can see a long list of compile commands. It will have Wire.cpp in it, with a full path.

thanks, found it
/Library/Arduino15/packages/SODAQ/hardware/samd/1.6.7/libraries/Wire.cpp

yes this is the version where the stopBit is used.
if (stopBit)
{
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);
}

so thats okay :smile:

Tip for formatting the post. If you insert 4 spaces at the start of a line it will show as “code” with non-proportional font. It will then also skip interpreting special characters like #

can we see the rest of this screenshot, so can compare with one that works (arduino pro mini) …

Just tested with an Arduino M0 Pro, and we have the same problem. all 0xFF data.
Later we will make some new screen shots :smile: