Shop OBEX P1 Docs P2 Docs Learn Events
help please — Parallax Forums

help please

RituRitu Posts: 39
edited 2006-07-26 19:39 in General Discussion
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

Comments

  • RituRitu Posts: 39
    edited 2006-07-20 19:21
    I have changed this code to:

    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?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-20 19:34
    You can store bytes into the javelin eeprom using
    EEPROM.write() and read those values back using EEPROM.read()
    You can start writing bytes from address 0 upwards.

    regards peter
  • RituRitu Posts: 39
    edited 2006-07-20 19:38
    Im sry to ask such basic questions but where in my code do I put those parts in, I am pretty confused.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-20 20:10
    See attachement.
    regards peter
  • RituRitu Posts: 39
    edited 2006-07-20 20:15
    How do I use that method later on? Or do I put it in the end of the main to begin with?
    thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-20 20:36
    There are several ways.
    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
  • RituRitu Posts: 39
    edited 2006-07-20 21:21
    Ok I have another very simple question. Here is part of my code, I have put in your readBack method in, but I am not sure exactly how to put it in, should it be CPU.readBack, or tempMeasurer.readBack or something else?
    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");
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-20 21:36
    See attachement.
    I made the storage of values a seperate routine.

    regards peter
  • RituRitu Posts: 39
    edited 2006-07-20 21:55
    The program is still not doing what I want it to do, I want to be able to tell the javelin sensor to figure out the temperature, then unhook it from the computer and move it into the fridge, which is when it should be calcuating the temperature. Then when I hook it up back to the computer I want it to tell me what temperatures it stored. How do I do this?
    Thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-20 22:50
    Ok, then you must rely on a pin to make the difference between storing data
    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
  • RituRitu Posts: 39
    edited 2006-07-21 14:18
    I am only getting zeros with this. How can I fix that
    Thanks
  • RituRitu Posts: 39
    edited 2006-07-21 14:25
    Also how can I save the information that comes out of my compass onto the javelin. The exact same way? My compass code is attached:
    Thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-21 14:34
    Sorry, my mistake.
    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-21 14:38
    You can store and retrieve compass data (or any data) the same way.
    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
  • RituRitu Posts: 39
    edited 2006-07-21 15:34
    Now that I have fixed that, when I put it in the fridge I get the same readings as I get when I use it in room temperature. Where could the problem lie? Is there a chance it is in the coding, or does it have to be the thermistor?
    Thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-21 17:06
    Perhaps your temperature sensor requires more time to settle for the lower
    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
  • RituRitu Posts: 39
    edited 2006-07-21 19:39
    What would be the most efficient way to write in the EEPROM stuff in my compass code? Since there are three pieces of data that I want to record, the x-axis, the y-axis, and the compass angle.
    Thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-21 19:47
    The easiest way is to store x,y and angle values as ints, in those order.
    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
  • RituRitu Posts: 39
    edited 2006-07-26 19:09
    What do I need to change in my code if I want to change the readings from 200 to 600, for around 5minutes of recordings?
    Thanks
  • RituRitu Posts: 39
    edited 2006-07-26 19:13
    something in here needs to change:

    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-26 19:39
    Make sure senseTemp has size 600:

    static int[noparse]/noparse senseTemp = new int[noparse][[/noparse]600];



    regards peter
Sign In or Register to comment.