help please
Hi,
I have been given the task of using a temperature sensor to calculate the temperature, adn I want all the data that it recieves to be saved so that after the test it can be accessed. The circuit I have made for it is the ADC example in the Javelin manual. This is the code I created, but I dont think the array I have made can be accessed again later. And is there any way to have the for loop go on forever, with an infinite array?
import stamp.core.*;
public class TempTester{
final static char CLS = '\u0010';
static ADC tempMeasurer = new ADC(CPU.pin9, CPU.pin8);
public static void main() {
int [noparse]/noparse senseTemp;
senseTemp = new int[noparse][[/noparse]200];
System.out.println("Please hold");
for(int i = 0; i < 200; i++)
{
senseTemp = tempMeasurer.value();
CPU.delay(1000);
System.out.println(i);
}
System.out.println("Temperature Sensor Data");
for(int j = 0; j<200; j++)
{
System.out.println(senseTemp[noparse][[/noparse]j]);
}
}
}
I would appreciate any help, this is a time sensitive project.
Thanks
I have been given the task of using a temperature sensor to calculate the temperature, adn I want all the data that it recieves to be saved so that after the test it can be accessed. The circuit I have made for it is the ADC example in the Javelin manual. This is the code I created, but I dont think the array I have made can be accessed again later. And is there any way to have the for loop go on forever, with an infinite array?
import stamp.core.*;
public class TempTester{
final static char CLS = '\u0010';
static ADC tempMeasurer = new ADC(CPU.pin9, CPU.pin8);
public static void main() {
int [noparse]/noparse senseTemp;
senseTemp = new int[noparse][[/noparse]200];
System.out.println("Please hold");
for(int i = 0; i < 200; i++)
{
senseTemp = tempMeasurer.value();
CPU.delay(1000);
System.out.println(i);
}
System.out.println("Temperature Sensor Data");
for(int j = 0; j<200; j++)
{
System.out.println(senseTemp[noparse][[/noparse]j]);
}
}
}
I would appreciate any help, this is a time sensitive project.
Thanks
Comments
import stamp.core.*;
public class TempTester{
final static char CLS = '\u0010';
static ADC tempMeasurer = new ADC(CPU.pin9, CPU.pin8);
public static void main() {
int [noparse]/noparse senseTemp;
senseTemp = new int[noparse][[/noparse]200];
System.out.println("Please hold");
for(int i = 0; i < 200; i++)
{
senseTemp = tempMeasurer.value();
CPU.delay(5000);
System.out.println(i);
}
System.out.println("Temperature Sensor Data");
for(int j = 0; j<200; j++)
{
System.out.println(senseTemp[noparse][[/noparse]j]);
}
while(true)
{
System.out.println("Type 'r' if the data needs to be repeated");
switch (Terminal.getChar())
{
case 'r':
{
for(int j = 0; j<200; j++)
{
System.out.println(senseTemp[noparse][[/noparse]j]);
}
}
default:
System.out.println("You did not type correct input yet");
}
}
}
}
The problem I still have though is how do I take out the information from the array later on?
EEPROM.write() and read those values back using EEPROM.read()
You can start writing bytes from address 0 upwards.
regards peter
regards peter
thanks
One way is to have more menu commands,
for example a command to read and store the adcvalues (the command you have now),
and another command to readback the stored values.
As I understand it, your ADC is disconnected later on,
so when you restart the javelin with the ADC disconnected,
you can select the second menu command.
regards peter
thanks
while (true) {
System.out.println("Type 'g' to start temperature reading");
System.out.println("Type 'r' if the data needs to be repeated");
switch (Terminal.getChar()) {
case 'g': {
for (int i = 0; i < 100; i++) {
senseTemp = tempMeasurer.value();
EEPROM.write(i*2+0,(byte)(senseTemp&0xFF)); //write low byte
EEPROM.write(i*2+1,(byte)(senseTemp>>>8)); //write high byte
CPU.delay(5000);
System.out.println(i);
}
}
case 'r': {
readBack();
}
default: System.out.println("You did not type correct input yet");
I made the storage of values a seperate routine.
regards peter
Thanks
and retrieving data. No need for a menu there.
In the attachement I used pin 9 for that purpose.
Ground pin 9, hook up the adc and battery, storing data starts in 10 seconds after
applying power so that gives you time to close the fridge door.
200 readings takes about 100 sec so the storing of data should be finished
2 minutes after applying power.
Open the fridge door, disconnect the battery, now hook pin9 to +5V, connect javelin to pc,
reconnect battery. Now the values are retrieved from eeprom, placed in array
and displayed.
regards peter
Thanks
Thanks
I used pin9 for storePin, but pin9 is used by the ADC.
Make storePin = CPU.pin10 and you should be able to store
and retrieve as described.
Note that to see output in the Javelin IDE after storing data,
you need to download the program again once the javelin
is reconnected to the pc (your stored data will not be overwritten).
regards peter
If you use both devices in one program, make sure the eeprom
addresses used for storing adc values does not overlap
the addresses used for storing compass data.
regards peter
Thanks
temperatures. You could add a longer delay at the start (currently
10 sec). You could increase it to 600 sec = 10 minutes, then take the
javelin out after 15 minutes in the fridge.
It is also possible the temperature inside the fridge is too
low for the javelin to function. I believe the javelin
is specified for 0 to 70 degree celsius.
Don't forget to hook pin10 to 5V before reconnecting to the pc.
regards peter
Thanks
For every compass measurement you then get 3 ints (6 bytes of eeprom storage).
How many samples do you want to store?
You can check the available eeprom storage space using
EEPROM.size() that returns the number of bytes you can
store in the eeprom. The longer your program, the less eeprom space
is available.
regards peter
Thanks
static void readBack() { //fill array senseTemp with values from eeprom
for (int i = 0; i < 600; i++) {
senseTemp = EEPROM.read(i*2+0)&0xFF; //read low byte
senseTemp |= (EEPROM.read(i*2+1)<<8); //read high byte
}
I dont knwo what
static int[noparse]/noparse senseTemp = new int[noparse][[/noparse]600];
regards peter