Hello i been trying to look for a way for the Lm35 Temperature sensor from the Slave Pro mini and show it on the Master Pro min though the I2c and the receiving side to display on the nokia 5110 lcd.
the problem I'm having is in serial monitor it shows correctly but when i try to print to lcd.print on the nokia 5110 i get a -1 and never changes or displays the temperature sketches are below. I'm not very good at coding to figure this out. i really need help.
Sender sketch
#include <Wire.h>
float temp;
int tempPin = 0;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
void loop()
{
Wire.beginTransmission(4); // transmit to device #4
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Wire.print("TEMPRATURE = ");
Wire.print(temp);
Wire.print("*C");
Wire.println();
Wire.endTransmission(); // stop transmitting
delay(2000);
}
Receive sketch
#include <PCD8544.h>
#include <Wire.h>
// A custom glyph (a smiley)...
static const byte glyph[] = { B00010000, B00110100, B00110000, B00110100, B00010000 };
static PCD8544 lcd;
void setup() {
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
// PCD8544-compatible displays may have a different resolution...
lcd.begin(84, 48);
// Add the smiley to position "0" of the ASCII table...
lcd.createChar(0, glyph);
}
void loop() {
// Just to show the program is alive...
// static int counter = 0;
// Write a piece of text on the first line...
//lcd.setCursor(0, 0);
//lcd.print("12345678901234");
// lcd.setCursor(0, 2);
//lcd.print("43210987654321");
//lcd.setCursor(0, 4);
// lcd.print("12345678901234");
lcd.setCursor(0, 0);
char c = Wire.read(); // receive byte as a character
lcd.print(c); // print the character
lcd.setCursor(0, 2);
int x = Wire.read(); // receive byte as an integer
lcd.print(x); // print the integer
delay(1000);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
lcd.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
lcd.print(x); // print the integer
}
// counter++;
can someone please help me out? thank you.
Still trying to figure this out.
Hello i mange to read the Lm35 from the sender node to the recieivng node and it shows correct.
Sender node
#include <Wire.h>
float temp;
int tempPin = 0;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
void loop()
{
Wire.beginTransmission(4); // transmit to device #4
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Wire.print("TEMPRATURE = ");
Wire.print(temp);
Wire.print("*C");
//Wire.println();
Wire.print();
Wire.endTransmission(); // stop transmitting
delay(2000);
}
receiving node
#include <Wire.h>
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
But i have one slight problem in it i can read the temperature but at the end it displays numbers that should not be there and i do not know what cause this or how to get rid of it, And now it shows Temperature = 20,51C10 there is a number 10 at the end.in the sender code there is a line Wire.println(); i seen something in google to get rid of it so i comment it out and i get Temperature = 20,5167 so something is wrong but i do not know what it is can someone please help me out. I got the original coding from arduini site master writting becuause i thought my first sketches was wrong it wasn't displaying anything on the receiving side http://arduino.cc/en/Tutorial/MasterWriter. So i use that sketch and added the lm36 to the sender side Can someone please help me out to fix this problem?
i get Temperature = 20,51*67
67 is the ASCII code for the letter C
You are reading the last character into an int so you get a number. Read it into a char and see what you get.
if i comment out that line Wire.println(); i get that but if its there i get Temperature = 20,51*C10 wit the 10 at the end i don't know what to make of it?
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
This prints everything except the final character as a char. So far, so good.
Using Wire.println(); sends a newline as the last character which you read as an int, hence seeing the 10 when you print it.
Hello UKHeliBob that does work awesome man I'm so happy man thank you so much man.
Hello UKHeliBobgot a question for you i have it working now so thank you so much i couldn't figure out why it was printing the 10 character at the end so thanks for helping me out was driving me nuts. Currntly the last part of my project is adding the 20x4 lcd to display the temperature from the receiver from the i2c so far that is no luck either this is what i came up with.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
lcd.begin(20,4);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
lcd.setCursor(0,0);
lcd.print("Hello");
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
lcd.setCursor(0,2);
lcd.print(c);
}
int x = Wire.read(); // receive byte as an integer
Serial.println();
lcd.setCursor(0,3);
lcd.println();
}
lcd.setCursor(0,2);
lcd.print(c);
That looks like it will print all the characters recieved over I2C onto one cell on the display. You need to place the cursor before this loop and then let the letters print in order.
Hint "no luck" is not helpful. What is the code supposed to do and what is the observed result or error message?
Hello morganS where at before the loop sorry i don't get it? you mean in the setup? or after this void receiveEvent(int howMany)
{
lcd.setCursor(0,2); like that?