Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: What type of variable on: October 26, 2013, 05:25:33 pm
Ah thanks!! I'll look on that.
2  Using Arduino / Programming Questions / What type of variable on: October 26, 2013, 05:16:54 pm
How do you call this type of variable and how to implement in the arduino IDE? I have searched but without the name its hard.
Example:
Person include person.name, person.age, person.adress etc...

Thanks
3  Using Arduino / Programming Questions / Re: Serial.Read() problem on: October 25, 2013, 07:32:35 pm
It's attached with my post (.ino) and there is also the pastebin link.
4  Using Arduino / Programming Questions / Re: Serial.Read() problem on: October 25, 2013, 06:48:55 pm
Thanks for the input.

Is just saw that for the first 4 or 5 transmisson, everything works fine..

Here is what happen.

The Serial buffer is 64 bytes long. If I only read 14 of them (number of bytes in my transmisson) the function Serial1.available return me those number after each time I send a packet:
63-49-35-21. The difference between those numbers are 14. I think the buffer is then overflowing.
**If I read the whole thing (64 bytes) everything it works fine, except in got my last 4.5 transmisson.
If I only wants to read 14 bytes each time, what should I do?
I tried Serial1.Flush();....nothing changed.
5  Using Arduino / Programming Questions / Serial.Read() problem on: October 25, 2013, 05:37:36 pm
So I got this weird error when reading from the serial port since a while.
IPlatform: Arduino Mega 2560
I am using a XBEE and when I read from the serial port I should receive the following bytes:
7E-0-A-81-0-1-24-0-55-22-20-22-55-4B.
I get this about 50% of the time. The other half I receive this:
0-55-22-20-22-55-4B-7E-0-A-81-0-1-24.
As you can see its look like 7 bytes are in the place of the other 7 bytes.
Rarelly I got this:  81-0-1-24-0-55-22-20-22-55-4B-7E-0-A

It look to me that the function Serial.Read start to read at a random time and I don't always have my start delimiter (7E) at the beginning.

This is my code, for debugging I add some serial.println so I could get what is in RxBuffer().
http://pastebin.com/XuWku1B1

Is there something I should do before calling Serial1.Read or do you know why I got such a thing??


Thanks



6  Using Arduino / Programming Questions / Re: MMA7361 Accelerometer on: May 19, 2013, 10:03:27 pm
EDIT 2****

I finally made it work..

Initialize the Serial1 Port AFTER calibrating the MMA7361 sensor.

I can't find the answer of why is it doing this, so I am asking you...does anyone knows???

Thanks
7  Using Arduino / Programming Questions / Re: MMA7361 Accelerometer on: May 18, 2013, 09:56:32 pm
EDIT*****

So, This is the problem I have after including accel.calibrate:

7E,0,A,81,0,1,24,0,0,80,80,80,0,FF,D9
IN READING FOR SERIAL
round passed 100ms
D9,7E,0,A,81,0,1,24,0,0,80,80,80,FF,CF
IN READING FOR SERIAL
round passed 100ms
0,D9,7E,0,A,81,0,1,24,0,0,80,80,FF,4F
IN READING FOR SERIAL
round passed 100ms
7F,0,DA,7E,0,A,81,0,1,24,0,0,80,FF,51
round passed 100ms
7F,0,DA,7E,0,A,81,0,1,24,0,0,80,FF,51
IN READING FOR SERIAL
round passed 100ms
80,7F,0,DA,7E,0,A,81,0,1,24,0,0,FF,F7
IN READING FOR SERIAL
round passed 100ms
80,80,7F,0,DA,7E,0,A,81,0,1,24,0,FF,F7
IN READING FOR SERIAL
round passed 100ms
0,80,80,7F,0,DA,7E,0,A,81,0,1,24,FF,78
IN READING FOR SERIAL
round passed 100ms
0,0,80,80,7F,0,DA,7E,0,A,81,0,1,FF,1C
IN READING FOR SERIAL
round passed 100ms
24,0,0,80,80,7F,0,DA,7E,0,A,81,0,FF,9D
round passed 100ms
24,0,0,80,80,7F,0,DA,7E,0,A,81,0,FF,9D
IN READING FOR SERIAL
round passed 100ms
1,24,0,0,80,80,7F,0,DA,7E,0,A,81,FF,9D
IN READING FOR SERIAL

You can see that the 7E (start delimiter) will shift to the right every two or three packets.

If I removed the accel.callibrate, I will receive clean data like this:

7E,0,A,81,0,1,24,0,0,80,80,7F,0,DA,DA
round passed 100ms
7E,0,A,81,0,1,24,0,0,80,80,7F,0,DA,DA
IN READING FOR SERIAL
round passed 100ms
7E,0,A,81,0,1,24,0,0,80,80,7F,0,DA,DA
IN READING FOR SERIAL
round passed 100ms
7E,0,A,81,0,1,24,0,0,80,80,7F,0,DA,DA
IN READING FOR SERIAL
round passed 100ms
7E,0,A,81,0,1,24,0,0,80,80,7F,0,DA,DA
IN READING FOR SERIAL
round passed 100ms
7E,0,A,81,0,1,24,0,0,80,80,7F,0,DA,DA
IN READING FOR SERIAL
round passed 100ms


Someone know why???


Thanks
8  Using Arduino / Programming Questions / Re: MMA7361 Accelerometer on: May 18, 2013, 04:27:39 pm
Yup, as I mentionned in my post, I removed all the Serial.print. But it make no difference. In my sketch I use Serial1, not Serial. 

Thank you anyway
9  Using Arduino / Programming Questions / Re: For loop on: May 18, 2013, 03:27:42 pm
Resetting/Initializing an array!! Putting 0x00 in every case for example.
10  Using Arduino / Programming Questions / MMA7361 Accelerometer on: May 18, 2013, 03:20:58 pm
Hi,

I made a sketch to comminunicate via 2 Xbee. All of this (rx_routine and tx_routine) work very well. I was adding the MMA7361 library to my project when evrything stop working (Communication worked ONCE per execution than nothing else).

I have already tested this library (alone) and everything was working fine. I found that if I remove the line  //accelero.calibrate();, everything would be working fine again (except the accelerometer).

I checked in the library why it would cause that but I couldn't see anything. (Just to be sure, I removed all the Serial.print, since I wasnt using this serial port, and wasnt working more)

Why it could do such thing??

Have any suggestion??

here is my code

Code:
#include <AcceleroMMA7361.h>


#define rx_lenght  14

//Accelerometer variables
AcceleroMMA7361 accelero;
int x;
int y;
int z;
int x_angle =0;
int y_angle =0;

unsigned char RxBuffer[rx_lenght], Rx_checksum;
unsigned char TxBuffer[20];
unsigned char checksum;
int valid_message_rx;    
int led = 27;            //LED on pin 27
int mess_received=0;
unsigned char TxXsum,TxXsum2;
int j;

unsigned long time_1=0, time_2=0, time;
unsigned long rs_1, rs_2;

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(9600);
  time_1 = millis();
  rs_1 = millis();
  pinMode(led, OUTPUT);

  accelero.begin(36, 37, 38, 39, A0, A1, A2);
  accelero.setARefVoltage(5); //sets the AREF voltage to 5V
  accelero.setSensitivity(LOW); //sets the sensitivity to +/-6G
  //accelero.calibrate();

}

void loop() {

  rx_routine();
  tx_routine();

  rs_2 = millis();
  if(rs_2 - rs_1 >= 1000){
    rs_1 = millis();
    x = accelero.getXAccel();
    y = accelero.getYAccel();
    z = accelero.getZAccel();

  }
}

void serialEvent1() {

  if(Serial1.available()>=rx_lenght) {
    for(int n=0; n <= (rx_lenght-1); n++){
      RxBuffer[n] = Serial1.read();
    }
    mess_received = 1;
  }
}


void rx_routine(){

  if(mess_received == 1){
    time_1 = millis();
    checksum = 0;
    for(int i=3; i <= 12; i++){
      checksum = checksum + RxBuffer[i];
    }
    Rx_checksum = 255 - checksum;
    if(RxBuffer[0] == 0x7E){
      if(RxBuffer[3] == 0x81){
        if(Rx_checksum == RxBuffer[rx_lenght-1]){
          digitalWrite(led, HIGH);
          valid_message_rx = 1;
        }
        else{
          valid_message_rx = 0;
          digitalWrite(led, LOW);
        }
      }
      else{
        valid_message_rx = 0;
        digitalWrite(led, LOW);
      }
    }
    else{
      valid_message_rx = 0;
      digitalWrite(led, LOW);
    }
    mess_received = 0;
  }

  time_2 = millis();           //Time out after a loss communication
  if(time_2 - time_1 >= 500){
    valid_message_rx = 0;
    digitalWrite(led, LOW);
  }

}

void tx_routine(){

  if(valid_message_rx == 1){

    TxBuffer[0] = 0x7E;
    TxBuffer[1] = 0x00;
    TxBuffer[2] = 0x10;
    TxBuffer[3] = 0x01;
    TxBuffer[4] = 0x00;
    TxBuffer[5] = 0x00;
    TxBuffer[6] = 0x01;
    TxBuffer[7] = 0x01;
    TxBuffer[8] = 0x55;
    TxBuffer[9] = x;
    TxBuffer[10] = y;
    TxBuffer[11] = 0x22;
    TxBuffer[12] = 0x22;
    TxBuffer[13] = 0x22;
    TxBuffer[14] = 0x22;
    TxBuffer[15] = 0x22;
    TxBuffer[16] = 0x22;
    TxBuffer[17] = 0x22;
    TxBuffer[18] = 0x55;

    TxXsum2 = 0;
    for(j=3; j <= 18; j++){
      TxXsum2 += TxBuffer[j];
    }
    TxXsum = 0xFF - TxXsum2;
    TxBuffer[19] = TxXsum;

    Serial1.write(TxBuffer,sizeof(TxBuffer));
    valid_message_rx = 0;

  }

}


11  Using Arduino / Programming Questions / Re: GPSbee on: April 20, 2013, 01:06:30 pm
I know how to put serial data into array and everything, but even in my GPS datasheet, they doesn't explain how the data comes out.

How many byte are we suppose to read at a time?
Why does reading (serial.read()) into an int give me all this data, including floatinf point??
12  Using Arduino / Programming Questions / Re: GPSbee on: April 20, 2013, 12:47:18 pm
What did Mr Google tell You? I'd Hate to duplicate your search...

Trust me, I searched for 3 hours, made a lot of tests. My question was how to separate the data in variables....there is really few examples out there.

Thanks PaulS for TinyGPS link.
13  Using Arduino / Programming Questions / GPSbee on: April 20, 2013, 02:53:03 am
Hi,

I am currently working on a project with a GPSbee and I wasn't able to find good example and explanation on how should I read the values of this device. The chip on it is a NEO-6M.
This is the result I am getting: http://imgur.com/a/9ZDdQ  

With u_center program, it seem to work but on the arduino IDE, it is just a mess of values. Currently this is my sketch:

Code:
/*-------------------------------------*/
/* GPS Bee Test Script                 */
int ledPin = 13;                  // LED test pin
int byteGPS=-1;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pins:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  
   digitalWrite(ledPin, HIGH);    // check if script works
   byteGPS=Serial.read();         // Read a byte of the serial port
   Serial.write(byteGPS);
   //Serial.write("\n");
   digitalWrite(ledPin, LOW);    // check if script works
}

So the question is: How can I separate all those values and store them in different variables?? Like longitude, lattitude...etc.

If some people have already worked with this device, sample code would be welcomed
14  Using Arduino / Project Guidance / Re: Low Battery Indicator monitoring battery for arduino on: March 26, 2013, 05:09:21 pm
1- Use a 9 or 12V battery...
2- Make a Voltage divider.
3 - Sense with Analog input.
4- No problem!
15  Using Arduino / Project Guidance / Re: RGB led and 2 pushbuttons on: March 25, 2013, 07:42:37 pm
I would simply ditch the internal resistor pull-up, use external one (pull-down) and use reverse logic.  LOW AND LOW for blue, HIGH LOW anf LOW HIGH for green or red.

Try this sketch with a slower refresh rate (2000).
Pages: [1] 2 3 4