Show Posts
Pages: 1 [2] 3 4 ... 13
16  Using Arduino / Programming Questions / Re: Can serial receive a byte and send it immediately? on: April 15, 2013, 01:34:25 am
Quote
Can you help me on how to modify it? Or my idea is not right? THX

Where you are sending data indirectly (Camera -> MCU -> PC)?

Quote
Sorry but I don't know how to send it byte by byte...

Code:
while( Serial1.available()>0){
    Serial.write(Serial1.read());
}

17  Using Arduino / Programming Questions / Re: SD Card Read -uint8_t from memory - help on: April 13, 2013, 06:56:38 am
May be i need to start a new discussion but it will mix up the things with previous topic.

Edit:
New discussion link: http://arduino.cc/forum/index.php/topic,160553.0.html
18  Using Arduino / Programming Questions / Re: How can i input a inverse tangent into arduino? on: April 13, 2013, 02:52:08 am
int bx= double    atan2 (double __4, double __12);

it said

sketch_apr13a:17: error: expected primary-expression before 'double'
sketch_apr13a:17: error: expected ',' or ';' before 'double'

how can i fix this problem? smiley-sad

Error come due to syntax of above statment;
double atan2 () is a builtin function of library.

Code:
// x should be initialize before this statment
double bx =   atan (x);
19  Using Arduino / Programming Questions / Re: How can i input a inverse tangent into arduino? on: April 13, 2013, 02:42:49 am
Or i need to add a library of math.h into my arduino?

http://arduino.cc/en/Math/H

Quote
I have tried to use atan into arduino but it didn't work.

Radian and Degree (Keep in mind) smiley-cool
20  Using Arduino / Programming Questions / Re: Ho to clear the Mega 2560 Serial1 data on: April 13, 2013, 01:34:45 am
Quote
How do you clear the data from the UART in the Mega?

Code:
if (Serial1.available())

This line answer your question very well. Serial1.available() > 0 means data available in buffer vice versa.
21  Using Arduino / Programming Questions / Re: SD Card Read -uint8_t from memory - help on: April 13, 2013, 01:26:17 am
That would be a good use for a union.

Hello again.

After some time giving to design of packet and some experiments i came to this format of packet

Code:
union uPacket{
  struct packet{
    char sDelimeter; //To mantian Backward Compatibilty
    uint8_t id;
    uint8_t payload[10];
    char mDelimeter; //To mantian Backward Compatibilty
    uint16_t msgId;
    char eDelimeter; //To mantian Backward Compatibilty
  }
  sPac;
  uint8_t asBytes[16];
}
uRx, uTx;

Quote
Cycle of Communication

                            NODE 1                                                    NODE 2
Fill(struct) -->Send(uTx.asBytes) -... ...- Recv(&buffer) -->copy(uRx.asBytes) -->extract(struct)

Suggestion required (anything need to keep in mind?).

Thanks in advance.
22  Using Arduino / Programming Questions / Re: SD Card Read -uint8_t from memory - help on: April 10, 2013, 09:26:48 am
Quote
Thats why i ask the above question may be someone using/used it in WSN application.
That would be a good use for a union. Sending binary data is faster than converting it to a string, sending the string, and then converting the string back to a numeric value. Partly because the number of bytes can be smaller, but also because the conversion steps are removed. The result is exact, to, not an approximation that is the result of converting the value to a string (and back).

Thanks, Your help and guidance really appreciable.

Good Night. smiley-cool
23  Using Arduino / Programming Questions / Re: SD Card Read -uint8_t from memory - help on: April 10, 2013, 09:09:50 am
Quote
By the way, if you name the union, you can create multiple instances of it, instead of redefining it for each instance.

Oops, i was in hurry

Code:

union
{                
  byte asBytes[4];  
  uint32_t asint;    
}                      
rxtst;

I was assuming this is the part of Node#2.

Quote
Are you reading binary data from a file? Is the binary data really unsigned long?

At this time ANSWER: NO. Actually i am thinking to use that kind of thing in Wireless Sensor Network(WSN). Thats why i ask the above question may be someone using/used it in WSN application.
24  Using Arduino / Programming Questions / Re: SD Card Read -uint8_t from memory - help on: April 10, 2013, 08:32:44 am
Quote
You are assuming that the 4 bytes of the unsigned long are going to look like regular characters. You'll note that the value I chose at random is more than 4 characters in length. But, it still fits in an unsigned long.

Code:
union {                
  byte asBytes[4];  
  uint32_t asint;    
}                      
txtst;

union {                
  byte asBytes[4];  
  uint32_t asint;    
}                      
rxtst;

void setup()
{
  Serial.begin(9600);
  
  txtst.asBytes[0] = 1;
  txtst.asBytes[1] = 2;
  txtst.asBytes[2] = 2;
  txtst.asBytes[3] = ',';
  
  Serial.println(txtst.asint ,HEX);
  Serial.println(txtst.asint ,DEC);
  Serial.println(txtst.asint ,BIN);
  
  //Reverse Process
  
  rxtst.asint = txtst.asint;
  
  Serial.println( rxtst.asBytes[0] );
  Serial.println( rxtst.asBytes[1] );
  Serial.println( rxtst.asBytes[2] );
  Serial.println( rxtst.asBytes[3] );
}

void loop()
{
  // nothing happens after setup
}

Quote
2C020201
738329089
101100000000100000001000000001
1
2
2
44

Thanks, now i got it how to use it.
Last question: Any suitable example of using it in any application
25  Using Arduino / Programming Questions / Re: SD Card Read -uint8_t from memory - help on: April 10, 2013, 07:40:08 am
Quote
Edit: if i am not wrong you want to read whole value 182 at a time as uint8_t.
It appears as though the file contains binary data, not ASCII data, and that the data represents 32 bit ints, using 4 bytes.

If that is the case, then reading the bytes one at a time, and populating the byte array of the union IS the correct approach.

The problem is that the union is defined incorrectly. Every element in the union needs to be exactly the same size. The uint8_t item is 8 bits. The 4 byte array is 32 bits. Not the same size at all.

If you change the uint8_t to uint32_t (or unsigned long), then both items in the union will be the same size.

First thanks for the correction.

To learn this new technique(for me). I tried this code but still confuse how to use it for useful purpose.

Code:
union {               
  byte asBytes[4];   
  uint32_t asInt[1];   
}                     
tst;

void setup()
{
  Serial.begin(9600);
 
  tst.asBytes[0] = 1;
  tst.asBytes[1] = 1;
  tst.asBytes[2] = 1;
  tst.asBytes[3] = ',';

  Serial.println(tst.asInt[0] ,HEX);
  Serial.println(tst.asInt[0] ,DEC);
  Serial.println(tst.asInt[0] ,BIN);
}

void loop()
{
 
}

Quote from: OUTPUT

2C010101
738263297
101100000000010000000100000001


I think so, I did some mistake.

Thanks
26  Products / Arduino Due / Re: Arduino DUE/ Changing Timer by Serial Monitor on: April 10, 2013, 01:10:18 am
The Due has a dedicated forum for discussing the board.

Ref: http://arduino.cc/forum/index.php/topic,144446.15.html

Library:  pwm01.h
Description:  A clean alternate approach for setting up unique PWM frequencies from within a sketch, for any or all PWM pins.  The trick is to utilize the two PWM clocks (CLKA & CLKB) provided by the SAM3X8E chip.

I wrote and enclosed a library (pwm01.h).  It includes 4 user functions to:  1) setup PWM resolution, 2) setup PWM pin, frequency & pick clock, 3) write duty cycle, and 4) stop PWM.  See example code for usage:

Code:
#include "C:\Programs\arduino-1.5.1r2\hardware\arduino\sam\libraries\Pwm01\pwm01.h"

void setup()
{
    uint32_t  pwm_duty = 32767;
    uint32_t  pwm_freq1 = 2;  
    uint32_t  pwm_freq2 = 5000;

    // Set PWM Resolution
    pwm_set_resolution(16);  

    // Setup PWM Once (Up to two unique frequencies allowed
    //-----------------------------------------------------    
    pwm_setup( 6, pwm_freq1, 1);  // Pin 6 freq set to "pwm_freq1" on clock A
    pwm_setup( 7, pwm_freq2, 2);  // Pin 7 freq set to "pwm_freq2" on clock B
    pwm_setup( 8, pwm_freq2, 2);  // Pin 8 freq set to "pwm_freq2" on clock B
    pwm_setup( 9, pwm_freq2, 2);  // Pin 9 freq set to "pwm_freq2" on clock B
      
    // Write PWM Duty Cycle Anytime After PWM Setup
    //-----------------------------------------------------    
    pwm_write_duty( 6, pwm_duty );  // 50% duty cycle on Pin 6
    pwm_write_duty( 7, pwm_duty );  // 50% duty cycle on Pin 7
    pwm_write_duty( 8, pwm_duty );  // 50% duty cycle on Pin 8
    pwm_write_duty( 9, pwm_duty );  // 50% duty cycle on Pin 9

    delay(30000);  // 30sec Delay; PWM signal will still stream
        
    // Force PWM Stop On All Pins
    //-----------------------------    
    pwm_stop( 6 );
    pwm_stop( 7 );
    pwm_stop( 8 );
    pwm_stop( 9 );
}

void loop()
{  
}


The pwm01.h library and example code were tested in IDE 1.5.1r2.  Additional notes on this library:
- Applies to Arduino-Due board, PWM pins 6, 7, 8 & 9.
- Libary Does not operate on the TIO pins.
- Unique frequencies set via PWM Clock-A ("CLKA") and Clock-B ("CLKB")
  Therefore, up to two unique frequencies allowed.
- Set max duty cycle counts (pwm_max_duty_Ncount) equal to 255 per Arduino approach.  
  This value is best SUITED for low frequency applications (2hz to 40,000hz) such as
  PWM motor drivers, 38khz infrared transmitters, etc.
- Future library versions will address high frequency applications.
- Arduino's "wiring_analog.c" function was very helpful in this effort.
27  Using Arduino / Programming Questions / Re: SD Card-Reading data from a "text file" then saving some text to other textfiles on: April 10, 2013, 12:49:25 am
Try to run only this portion in setup()

Code:
File dataFile = SD.open("log.txt",FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
  dataFile.println("Sample time stamps....");
  dataFile.close();
}
else
{
  Serial.println("Getting Error")
}
then check the file in sd card for data if the result seems fine next time put some delay before the above portion in loop e.g.

Code:
.
.
.
delay(100);
File dataFile = SD.open("log.txt",FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
  dataFile.println("Sample time stamps....");
  dataFile.close();
}
else
{
  Serial.println("Getting Error")
}
28  Using Arduino / Programming Questions / Re: SD Card Read -uint8_t from memory - help on: April 10, 2013, 12:11:45 am
.................. and I want to read the data I have in the SD, in a uint8_t.

No, you can not read the date in(as a ) uint8_t.

1) "184," is equal to 4bytes in your txt.
2) read the 184 in any buffer(by any logic which you like e.g parsing, use of delimeter",") Edit: myFile.read(foo.asBytes, 3) reads the first  three byte of file
3) then convert this buffer into integer e.g atoi Edit: My mistake, thanks for the correction (PaulS)

Edit: if i am not wrong you want to read whole value 182 at a time as uint8_t.
29  Using Arduino / Programming Questions / Re: Need some basic help with programming on: April 09, 2013, 11:52:04 pm
Hello Osgeld,

The error message that I included in my post tells me that x() is not a function. What is a function in c++? When I Google the error message I get no useful information. What I'm looking for is an example code snip to accomplish printing an incrementing variable to my lcd.

Thanks
jessey

If you Google the "What is a function in c++?"  you will get ...
30  Using Arduino / Programming Questions / Re: xbee and arduino due on: April 08, 2013, 07:01:37 am
I am using xbee library.
the example is for a communication between two xbee serie 1.
here the code of the transmitter (serie1_Tx) :

....
there is an include NewSoftSerial , (which can be changed SoftwareSerial) which is the source of the error with the arduino due  smiley-sad-blue

And

Quote
Not unless the code is driving some servos to install jumper wires to connect your XBees to a hardware serial port.

PaulS, have you an idea how it can be done in this case ?


Here is an example of XBEE HW serial.
https://code.google.com/p/xbee-arduino/source/browse/trunk/examples/Series1_Tx/Series1_Tx.pde

and one of those are pins which you need to connect with xbee

Serial: 0 (RX) and 1 (TX)
Serial 1: 19 (RX) and 18 (TX)
Serial 2: 17 (RX) and 16 (TX)
Serial 3: 15 (RX) and 14 (TX)

REF:http://arduino.cc/en/Main/ArduinoBoardDue

e.g.

1(TX) on Due ................... DIN on xbee explorer.

0 (RX) on Due................... DOUT on xbee explorer.

GND ............... GND

VCC ................ VCC

Please verify them according to your module and Due datasheet.
Pages: 1 [2] 3 4 ... 13