13
tips for fishtank programming living with the lab =1274.1 0.1325 =3.6686 ( 10 ) 24 7.5472 2013 David Hall

Tips for fishtank programming living with the lab © 2013 David Hall

Embed Size (px)

Citation preview

tips for fishtank programming

living with the lab

𝑜𝑢𝑡𝑝𝑢𝑡=1274.1∙ 𝑠𝑎𝑙𝑖𝑛𝑖𝑡𝑦0.1325

𝑠𝑎𝑙𝑖𝑛𝑖𝑡𝑦=3.6686 (10 )−24 ∙𝑜𝑢𝑡𝑝𝑢𝑡7.5472

© 2013 David Hall

write an Arudino program to compute salinity

2

living with the lab

𝑠𝑎𝑙𝑖𝑛𝑖𝑡𝑦=3.6686 (10 )−24 ∙𝑜𝑢𝑡𝑝𝑢𝑡7.5472

what data type should we useto store the salinity?

what data type should we useto 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

tip 2: take small steps & verify the result of each step

3

living with the lab

print out EVERYTHING you calculate

4

living with the lab

look on the LWTL website if you can’t remember how to print things out

don’t worry about this part right now

tip 2 example: small steps with verification

5

living with the lab

𝑠𝑎𝑙𝑖𝑛𝑖𝑡𝑦=3.6686 (10 )−24 ∙𝑜𝑢𝑡𝑝𝑢𝑡7.5472

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 enterthis 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!

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.

𝑠𝑎𝑙𝑖𝑛𝑖𝑡𝑦=3.6686 (10 )−24

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); }

𝑠𝑎𝑙𝑖𝑛𝑖𝑡𝑦=3.6686 (10 )−24

from LCD program:

Change the print command to something like this and run the program:

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); }

𝑠𝑎𝑙𝑖𝑛𝑖𝑡𝑦=3.6686 (10 )−24 ∙𝑜𝑢𝑡𝑝𝑢𝑡7.5472

comment out your analogRead statement and just enter an estimated

value for the output so that youcan check your calculations!

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?

𝑠𝑎𝑙𝑖𝑛𝑖𝑡𝑦=3.6686 (10 )−24 ∙𝑜𝑢𝑡𝑝𝑢𝑡7.5472

you MUST check this numberon your calculator or in Excel . . . not doing so is just asking for trouble

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.

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 programa. 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

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");

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