Chirp! Issues

I’m currently playing around with a Chirp! unit and I’m running into some strange issues with the module. I’m using this code from the developer and I keep getting strange results where the light reading will be the same as the capacitance reading and the temperature reading seems off as well.

Capacitance: 69835 Temp: -1.0 Light 69835 (or sometimes blank)

Has anyone used this module before or see something obvious that I’m doing/something in the code? It was working fine a few days ago so I’m not sure what has changed as I’ve been playing with the code but now this one doesn’t seem to work with no modification.

http://wemakethings.net/chirp/ Link to developer site.

/*
I2C sensor - arduino example

Connection 
Chirp pin 1 - no connection
Chirp pin 2 - Arduino VCC
Chirp pin 3 - Arduino A5
Chirp pin 4 - Arduino A4
Chirp pin 5 - no connection
Chirp pin 6 - Arduino GND
*/
#include <Wire.h>

void writeI2CRegister8bit(int addr, int value) {
  Wire.beginTransmission(addr);
  Wire.write(value);
  Wire.endTransmission();
}

unsigned int readI2CRegister16bit(int addr, int reg) {
  Wire.beginTransmission(addr);
  Wire.write(reg);
  Wire.endTransmission();
  delay(20);
  Wire.requestFrom(addr, 2);
  unsigned int t = Wire.read() << 8;
  t = t | Wire.read();
  return t;
}

void setup() {
  Wire.begin();
  Serial.begin(9600);
  writeI2CRegister8bit(0x20, 6); //reset
}

void loop() {
  Serial.print(readI2CRegister16bit(0x20, 0)); //read capacitance register
  Serial.print(", ");
  Serial.print(readI2CRegister16bit(0x20, 5)); //temperature register
  Serial.print(", ");
  writeI2CRegister8bit(0x20, 3); //request light measurement 
  Serial.println(readI2CRegister16bit(0x20, 4)); //read light register
}

Uh....

How can we be getting a number >65K out of an unsigned int?

Uh....

How can we be getting a number >65K out of an unsigned int?

Use a Due.

PaulS: Use a Due.

I have not used anything besides an Uno at this point, why would a Due be a better choice? Sorry if this is an obvious answer question too.

And I was going off memory for the capacitance reading, it was the same as the light so I was worried it was the code possibly reading the same info for the light and capacitance.

I have not used anything besides an Uno at this point

There is something wrong with your sample output, then. The unsigned int value can not hold 69835.

Noige:
I have not used anything besides an Uno at this point, why would a Due be a better choice? Sorry if this is an obvious answer question too.

And I was going off memory for the capacitance reading, it was the same as the light so I was worried it was the code possibly reading the same info for the light and capacitance.

It wouldn’t.

I asked how a value of 69000-some could possibly be printed for an unsigned int, since unsigned int could not store something greater than 65531 (2^16-1). Paul suggested that you must be using a Due, since there the unsigned int is 32 bits (so up to 4.2 billion)

Therefor, we have a real mystery for that output.

Or are you saying that you made up those numbers? If so, go get the real numbers and post them, otherwise you’re just wasting your time and ours.

I see this a lot here, and I just do not understand it. People make up output that they think looks kinda like how they remember it - you have the code, you have the hardware, why can you not provide the actual output? If the answer is “I’m not home now”, then you should wait to post until you are home and have access to the actual output string!

DrAzzy: It wouldn't.

I asked how a value of 69000-some could possibly be printed for an unsigned int, since unsigned int could not store something greater than 65531 (2^16-1). Paul suggested that you must be using a Due, since there the unsigned int is 32 bits (so up to 4.2 billion)

Therefor, we have a real mystery for that output.

Or are you saying that you made up those numbers? If so, go get the real numbers and post them, otherwise you're just wasting your time and ours.

I see this a lot here, and I just do not understand it. People make up output that they think looks kinda like how they remember it - you have the code, you have the hardware, why can you not provide the actual output? If the answer is "I'm not home now", then you should wait to post until you are home and have access to the actual output string!

You're exactly right, not at home at the moment. I know that value was high and matching the light value so I was thinking it was something in the code. I didn't realize I was so close to the upper limit of the unsigned int otherwise I wouldn't have gone off memory. It very well could have been 65531 but I don't know enough about the unsigned int to know if it will produce that value if readings exceed it's max output.

Still learning a lot about this stuff so I appreciate your patience and will post specific outputs when I'm home.

The value that I was receiving for the capacitance was actually 65531 which is not right. I started to think I had a communication problem with the I2C so I ran the I2C scanner and it gets stuck on "scanning".

Put on an LCD (I2C comm.) and it read the 0x20 address fine and also checked a motor shield with no issues.

I'm beginning to think it's an I2C communication issue. Following the setup for the original code I have the following hooked up. Arduino A5 and A4 I have a 4.6k pull up resistor to 5v. I have tried a 10k resistor with similar results.

Connection Chirp pin 1 - no connection Chirp pin 2 - Arduino VCC Chirp pin 3 - Arduino A5 Chirp pin 4 - Arduino A4 Chirp pin 5 - no connection Chirp pin 6 - Arduino GND

Not sure if there is an issue with my wiring or what at this point.

Hey

I have been using the chirp to display the output to a i2c lcd and I am using similar code as yours (after changing it to lcd) but the values are messed up. So the light value is always 65535, and is printed in the temp line. and the temp value is printed on the light line.

//#include <I2CSoilMoistureSensor.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//I2CSoilMoistureSensor sensor;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {
Wire.begin();
lcd.init(); // initialize the lcd .
lcd.backlight();
writeI2CRegister8bit(0x20, 6); //reset
}

void writeI2CRegister8bit(int addr, int value) {
Wire.beginTransmission(addr);
Wire.write(value);
Wire.endTransmission();
}

unsigned int readI2CRegister16bit(int addr, int reg) {
Wire.beginTransmission(addr);
Wire.write(reg);
Wire.endTransmission();
delay(20);
Wire.requestFrom(addr, 2);
unsigned int t = Wire.read() << 8;
t = t | Wire.read();
return t;
}
void loop() {
lcd.setCursor(0,0);
lcd.print("S M C: "); // soil moisture capacitance
lcd.print(readI2CRegister16bit(0x20, 0)); //read capacitance register

lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(readI2CRegister16bit(0x20, 5)/float(10)); //read Temp register

lcd.setCursor(0,2);
writeI2CRegister8bit(0x20, 3); //request light measurement
delay(3000);
lcd.print("Light: ");
lcd.print(readI2CRegister16bit(0x20, 4)); //light register

delay(8000);
lcd.clear();

}

this is the code I am using. Initially I thought that the registers are different but that did not work. do you have any suggestions.