Ladies and Gents,
Project final goal : Display Temp data on Leds through expander
I am trying desperately to light up the leds on Pikit I2C demo board, which are connected to MCP23008 output.. but I can't get any results. I also trying to get temperature from Temp Sensor (MCP9800) but couldn't get any results. Here is the following code : which i extracted from the forums. I don't see any error in the lines, why am I not getting the leds turned on or temp back ?
Using Arduino Uno
Got A4 connected to SDA
A5 connected to SCL
Chips addresses are included on the board (0x40) for expander and 0x92 for temp sensor
the PICkit board has 2 pullup resistors 1.5k
MCP23008 Expander to leds
//#include <Wire.h>
#include <Wire.h>
//Arduino analog input 5 - I2C SCL
//Arduino analog input 4 - I2C SDA
void setup() {
Wire.begin(); // initialise the wire library and hardware
Wire.beginTransmission(0x40); // start talking to the device
Wire.write(0x00); // select the IODIR register
Wire.write(0x00); // sets all pins as outputs on MCP23008
Wire.endTransmission(); // stop talking to the devicevice
delay(500);
}
//byte x = 0;
void loop() { //blink leds
Wire.beginTransmission(0x40); // start talking to the device
Wire.write(0x09); // select the GPIO register
Wire.write(0xff); // set register value-all high
Wire.endTransmission(); // stop talking to the device
//delay(500); // wait for 1/2 a second
Wire.begin(); // initialise the wire library and hardware
Wire.beginTransmission(0x40); // start talking to the device
Wire.write(0x09); // select the GPIO register
Wire.write(0x00); // set register value-all low
Wire.endTransmission(); // stop talking to the device
// x++ ;
delay(500); // wait for 1/2 a second
}
Temp sensor
#include "Wire.h"
//wire library
#define address 0x92
//address of the temperature sensor
#define delayC 1000
//delay count in ms
#define baudrate 9600
//baudrate for communication
void setup()
{
Wire.begin();
Serial.begin(baudrate);
}
void loop()
{
Serial.print("temperature in Celsius: ");
//let's signal we're about to do something
int temperature;
//temperature in a byte
Wire.beginTransmission(address);
//start the transmission
Wire.write(0x00); //ambient temp register
Wire.requestFrom(address, 1); //read
if (Wire.available()) { //is data available
temperature = Wire.read(); //assign it to variable
Serial.println(temperature);
} else {
Serial.println("---");
}
Wire.endTransmission();
//end the transmission
delay(delayC);
}
Source :
Temp sensor