Loading...
  Show Posts
Pages: [1] 2 3 4
1  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
2  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
3  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
4  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.
5  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;

  }

}


6  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??
7  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.
8  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
9  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!
10  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).
11  Using Arduino / Project Guidance / Re: Help LED dim on: March 25, 2013, 07:38:10 pm
You should use a Rx buffer then take for example Rxbuffer[1] to be the value of your brightness.

Rxbuffer[0] = Start delimiter //0x7E
Rxbuffer[1]=Value
Rxbuffer[2]=END //Checksum

This mean send an array, receive an array.

What is sending value to your arduino?

Always use If serial availble>= VALUE
12  Using Arduino / Project Guidance / Re: Bass guitar string sensor? on: March 13, 2013, 01:58:41 pm
Are you talking about something similar to this???

http://i.imgur.com/q54jDlN.jpg

Those are use in the making of guitar pickups. You then use some differential and integral calculus of the output of the sensor and you got it...
13  Using Arduino / Programming Questions / Re: Basic Serial on: March 13, 2013, 12:32:53 pm
First, you need to save all the byte you see on the serial port (for 1 transmisson) just like this:

Code:
void serialEvent() {

unsigned char RxBuffer[14];

  if(Serial.available()>=14) {

    for(int n=0; n <= 13; n++){
       RxBuffer[n] = Serial.read();
    }
  }
}

After this, make a function name something like Rx_check();

Code:
void check_rx(){

  switch(RxSerialState)
  {  
  case 0:                     //  Check for Start Delimiter
    if(RxBuffer[0]== 0x7E){
      RxSerialState=1;
      RxXsum=0x00;
      ValidMsgRxied=0;
      RxError=0;              
    }
    else
      RxSerialState=0;        
    break;  

  case 1:                     // Read Byte Count High              
    RxSerialState=2;
    break;

  case 2:                     // Read Byte Count Low  
    RxByteCount = RxBuffer[2];        
    if ( (RxByteCount < 30) || (RxByteCount > 0) )
      RxSerialState=3;
    else
      RxSerialState=0;
    break;

  case 3:                     // Read API ID
    RxXsum = RxXsum + RxBuffer[3];
    p=4;  
    RxByteCount--;
    if ( RxBuffer[3] == 0x81){           // API Type=0x81 sur XBEE;
      RxSerialState=4;
    }
    else
      RxSerialState=0;
    break;

  case 4:                     // Read Data
    RxXsum=RxXsum+RxBuffer[p];
    p++;
    if (RxByteCount == 0)
    {
      RxSerialState=5;
      RxXsum=255-RxXsum;
    }
    RxByteCount--;
    break;

  case 5:                     // Read XSUM
    if ( (RxXsum==RxBuffer[p]) && (RxByteCount == 0) )
    {
    ValidMsgRxied=1;
    RxSerialState=0;
    }
    else
       RxError=1;
    break;
  }   // end switch

}

This will do the job just fine
14  Using Arduino / Programming Questions / Re: RF link transmitter and Receiver pair on: March 12, 2013, 04:41:40 pm
You should use :   for the transmitter

Code:
#include <VirtualWire.h>

void setup()
{

  pinMode(13, OUTPUT);

  vw_set_ptt_inverted(true);  
  vw_setup(2000);            // Bits per sec
  vw_set_tx_pin(3);          //Tx pin
  
}


void loop()
{
  
  delay(100);               //Send a message every half second

  
  char *msg = "12321";
  digitalWrite(13, HIGH ); // Flash a light to show transmitting
  vw_send((byte *)msg, strlen(msg));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13, LOW);


}


and :   for the receiver.

Code:
#include <VirtualWire.h>


int i =0;
int msg_received = 0;

void setup()
{

  Serial.begin(9600);
  Serial.println("Started");
  
  vw_set_ptt_inverted(true);
  vw_setup(2000);         // Bits per sec
  vw_set_rx_pin(2);              //Rx pin
  vw_rx_start();              

  pinMode(13, OUTPUT);  

}

void loop()
{


  byte buf[VW_MAX_MESSAGE_LEN];
  byte buflen = VW_MAX_MESSAGE_LEN;

 
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    
    digitalWrite(13, HIGH);
    
    Serial.print('\n');
    Serial.println("Receiving data");
    Serial.print('\n');
    
    for (i = 0; i < buflen; i++)
    {
      Serial.print(buf[i]);
    }
    
    for (i = 0; i < buflen; i++)
    {
      buf[i] = buf[i] -48;
    }
    Serial.print('\n');
    for (i = 0; i < buflen; i++)
    {
      Serial.print(buf[i]);
    }
    
    Serial.print('\n');
    Serial.print("------------------------");
    
    
    delay(10);
    digitalWrite(13, LOW);
    
  }
}

Dont forget to use the lastest librairy virtualwire 1.14.

15  Using Arduino / Programming Questions / int to char and concatenate char on: March 12, 2013, 04:34:54 pm
Hi,

Here is an example code I took and modified for my purpose with an 315MHz transmitter.

Currently, I test it by changing value in variable char *msg = "12321";

What about if I want to send some sensors value? I put some random variable at the top of the code, volt and temp. How should I convert those to concatenate to form the same variable type as char *msg?



Thanks


Code:
#include <VirtualWire.h>

int temp = 25 ;
int volt = 5 ;

void setup()
{

  pinMode(13, OUTPUT);

  vw_set_ptt_inverted(true); 
  vw_setup(2000);            // Bits per sec
  vw_set_tx_pin(3);          //Tx pin
 
}


void loop()
{
 
  delay(100);               //Send a message every half second

 
  char *msg = "12321";
  digitalWrite(13, HIGH ); // Flash a light to show transmitting
  vw_send((byte *)msg, strlen(msg));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13, LOW);


}
Pages: [1] 2 3 4