Download presentation
Presentation is loading. Please wait.
Published byPosy Cannon Modified over 9 years ago
1
tips for fishtank programming living with the lab © 2013 David Hall
2
write an Arudino program to compute salinity 2 living with the lab what data type should we use to store the salinity? what data type should we use to store the output? go to the arduino.cc website to see if you can figure out which data type might be best tip 1: use the correct data type
3
tip 2: take small steps & verify the result of each step 3 living with the lab print out EVERYTHING you calculate
4
4 living with the lab look on the LWTL website if you can’t remember how to print things out
5
don’t worry about this part right now tip 2 example: small steps with verification 5 living with the lab how do we enter this number? double salinity; void setup() { Serial.begin(9600); } void loop() { salinity = Serial.println(salinity); } try to figure out how to enter this number Don’t go to the next slide until you play around a few minutes, trying to figure this out on your own. Learning how to figure out things that you don’t know is an important part of programming!
6
tip 2 example continued: 6 living with the lab double salinity; void setup() { Serial.begin(9600); } void loop() { salinity = 3.6687E-24; Serial.println(salinity); } The program seems to work, but only zeros are printed. How can we fix this? HINT: We did something similar when working with the LCD screen.
7
tip 2 example continued: 7 living with the lab double salinity; void setup() { Serial.begin(9600); } void loop() { salinity = 3.6687E-24; Serial.println(salinity); } from LCD program: Change the print command to something like this and run the program:
8
tip 3: put in dummy values so calculations can be checked 8 living with the lab double salinity; int output; void setup() { Serial.begin(9600); } void loop() { // output=analogRead(0); output=500; salinity = 3.6687E-24*pow(output,7.5472); Serial.println(output); Serial.println(salinity,29); } comment out your analogRead statement and just enter an estimated value for the output so that you can check your calculations!
9
tip 4: check EVERY number you compute 9 living with the lab double salinity; int output; void setup() { Serial.begin(9600); } void loop() { // output=analogRead(0); output=500; salinity = 3.6687E-24*pow(output,7.5472); Serial.println(output); Serial.println(salinity,29); } Where did we fine out how to use the “pow” function? you MUST check this number on your calculator or in Excel... not doing so is just asking for trouble
10
tip 5: format your print statements to keep track of things 10 living with the lab double salinity; int output; void setup() { Serial.begin(9600); } void loop() { // output=analogRead(0); output=500; salinity = 3.6687E-24*pow(output,7.5472); Serial.print("output = "); Serial.print(output); Serial.print(" salinity = "); Serial.println(salinity,29); } Comment out print statements when you are done with them, just in case you need them later.
11
tip 6: save all your old programs dealing with hardware 11 living with the lab Generally, if an old program doesn’t work anymore, then you have a HARDWARE problem (assuming things are wired to the same pins as in the original program). Isolating the problem as hardware or software related is a critical troubleshooting step. Most of the old programs are on the LWTL site under “content” if you lose them for some reason. (1)your conductivity calibration program a.if you start getting erroneous readings from your conductivity sensor, then rerun the calibration program. b.if it doesn’t work correctly, then you have a HARDWARE problem. c.if it does work correctly, then you have a SOFTWARE problem. (2)your original LCD program (3)a program to make the solenoid valves click on and off
12
tip 7: put “i am here” statements in your functions 12 living with the lab Serial.print("opening salty valve"); Serial.print("in upper main loop"); Serial.print("just finished measuring conductivity");
13
tip 8: restrain yourself people 13 living with the lab resist the temptation of typing in large chunks of code before checking program flow and calculation accuracy remember that you are a systematic problem solving machine
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.