DATALOGGING WITH A POTENTIOMETER
Since datalogging and working with PHP is an unfamiliar task, I decided to start datalogging the values of a 10K potentiometer. This way, I know I am easily getting values that I can send to the net. Working with a potentiometer makes me avoid worrying if my sensor is part of any problems I may encounter in this task.
These are the steps I took to complete this assignment:
1. Create a simple circuit with a 10K pot hooked onto the ADCIN 0 of a PIC 18F452
2. Create a simple code for the PIC to read values from the pot and send it to PROCESSING. This code will be part of a 'call and response' system with Processing.
ADCIN 0, adcVar
SERIN2, portc.7, 16468 [inByte]
SEROUT2, portc.6, 16468 [adcVar]
- Note: In the above code, the SERIN command acts as a 'block' which stops the code from running until an 'inByte' has been received. No 'if' statement needs to be done.
3. Write the Processing code which involves the following tasks:
After I 'personalized' Tom's code, I tested it with my PIC. It was not problem free. First, I could not get values from the Potentiometer. Processing does not seem to be reading anything. I, then, inserted a 'print' statement within my serial event part of the code to view the sensorValue. Nothing seems to be coming out, or, at certain instances, one value comes out but does not change when I turn the pot knob. Eventually, I realized (with some help from Doria's magic hands) that my serial cable-header connection was not stable.
When that problem was resolved, I tried running the Processing program again. This time, I got this message alert:
I did not anticipate a 'non-write-enabled' text problem at all. I did not know how to resolve this and emailed Tom for help. Tom said, it needed to be write-enabled, naturally. He then instructed me to log on to my account and change to the directory where my text file is and type the following command:
chmod ugo+rw datalog.txt
The documentation to explain the above command, along with other simple PHP instructions can be found here.
4. Finally, write the PHP script and save it in my account's public folder, along with an empty '.txt' file where all my values will be stored.