Genoss
August 3, 2016, 11:24am
#1
#include <SoftwareSerial.h>
float Gewicht = 0;
int masse = 0;
float tara;
void setup() {
Serial.begin(9600);
Serial3.begin(9600);
//Mittelwert von tara
for (int i = 0; i < 500; i++) {
tara = tara + Serial3.read();
}
tara = tara / 500;
Serial.println(tara);
}
void loop() {
float sensorValue = 0;
//Mittelwert des Messwertes
for (int i = 0; i < 500; i++) {
sensorValue = sensorValue + Serial3.read();
}
sensorValue = sensorValue / 500;
Gewicht = ((sensorValue - tara) / 0.2173);
masse = Gewicht;
Serial.print("Messwert: “);
Serial.print(sensorValue);
Serial.println(” = “);
Serial.print(masse);
Serial.println(” gramm ");
delay(1000);
}
this is my code, but the compilation error says the Serial3 on line sensorvalue=sensorvalue + Serial3.read
And i have no idea why, please help me.
Did you select the right board under tools --> board?
And you don't need to include SoftwareSerial.h
Lastly, please use code tags when posting code (you can edit your opening post)
type
** **[code]** **
paste your code after that
type
** **[/code]** **
after that.
J-M-L
August 3, 2016, 11:39am
#3
You probably are still compiling for a UNO
Change the board type to the MEGA you have and your will be fine
Genoss
August 3, 2016, 11:49am
#4
Thank you very much, I was still using UNO because i am switching all the time.
Do you maybe know how to change my code so that it saves to the sd card( i have a breakoutboard attached) . I thought of the Library SD card but i am not sure if it works.
J-M-L
August 3, 2016, 12:28pm
#5
Well no I don't because I don't know what you want to save, how often etc...
Yes you can use the SD library - just take one of the examples you'll see it's very self explanatory
Start the SD card library
Open a file
Write a string in the file or binary data
Close the file
Loop and start again after a while (like every minute or something)