Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Float value through Serial Port.. on: April 04, 2008, 04:44:43 pm
Quote
Ok.. ok... about the "union" function i need any library to do this???

A union is not a fuction .... it is a union  smiley

Look up the union construct in C++ (which is really what we are using on the Arduino), for example http://www.cplusplus.com/doc/tutorial/other_data_types.html

A union is a structure where the members share the same location in memory. So we can access it as different data types. In this case assign as bytes and read as float.  smiley
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Binary serial communication on: April 18, 2008, 04:55:35 am
Quote
I know what you are saying / asking for. If you do
Do this:
Code:
Serial.print( 5, BYTE );

That'll do ya.

Thank you, I will have a look at this option. Combined with the union technique it may solve the problem.
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Binary serial communication on: April 04, 2008, 02:25:10 pm
Quote
I would like to know what the native floating point representation is, is it for example IEEE 754

I just discovered that another thread on this forum seems to confirm IEEE 754
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207242838

So I guess the union method might work....  smiley
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Binary serial communication on: April 04, 2008, 01:39:33 pm
Quote
Apologies if this comes across as unkind. Truely: Not meant that way!
.

Thank you for answering and for your good intent. However, I think you don't quite understand what I mean  smiley-wink. Of course, everything on the computer is binary, including ASCII text. That is not the issue.

When computing with numbers, the native number representation is something else than ASCII. I would like to know what the native floating point representation is, is it for example IEEE 754  http://en.wikipedia.org/wiki/IEEE_floating-point_standard or something else? As the original question states, I think it would be a good idea if such numbers could be transported over the serial port after being prepared to the relevant native format for the Arduino on the PC. That way no text to binary conversion would be needed on the Arduino.


5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Binary serial communication on: April 04, 2008, 03:26:07 am
Quote
Well the only way i know to send raw bytes is doing this:
Serial.print(byte(0xFF)); //Where 0xFF is the byte in hex you want to send

Ok, thanks that will be useful. I was initially thinking more about receiving binary data from the PC however, so will the serial read allow raw bytes too? And the question regarding binary representation of floats on the Arduino remains, since the PC will have to construct them properly if binary floats are to be sent over.
6  Forum 2005-2010 (read only) / Syntax & Programs / Binary serial communication on: April 03, 2008, 01:57:34 pm
I have a Diecimila and serial communication using ASCII is working fine. But string manipulation isn't really what the Arduino should be doing so I was wondering if there is a tutorial somewhere showing binary serial communication? I.e. with int and float values in binary format, not ASCII.

Which binary number representations does the Arduino use? I think the program (written in C++) on the PC side could construct the binary representation before sending it over the serial port so that the Arduino did not have to do any reformatting.

Has this been done?
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Debugging errors.. Returning an array from a F on: April 01, 2008, 08:20:46 am
Quote
Also keep in mind that arrays are not passed by value (using copies of its arguments) they are passed by reference (using the variables the calling function uses). That is to say, any change you make to items in the array in a function will be reflected in the same array that the calling function passed into it

This is almost correct  smiley-wink . In C and C++ "an array is a pointer". In this case an array was passed as parameter, i.e. a pointer was passed ---- that pointer is passed by value and not by reference.

// a function taking a single integer by value
void func1(int by_value) {}

// a function taking a single integer by reference
void func2(int& by_ref) {}

// a function taking a single integer by pointer (the pointer is passed by value)
void func3(int* by_pointer) {}

// a function taking a single integer by pointer (the pointer is passed by reference)
void func4(int*& by_pointer_ref) {}

// function taking an array (=pointer by value) and length of array (as int by value)
void func5(int array[], int arrayVals){}

// function taking a pointer (=array) and length of array (as constant int by reference)
void func6(int* array, const int& arrayVals){}

 :smiley


8  Forum 2005-2010 (read only) / Syntax & Programs / Re: String Questions on: March 23, 2008, 08:17:50 pm
Quote
So I am looking for some help or a point in the right direction to find out who to create strings on the fly. Looking to have Arduino go though some random array of text and put three or four words together into one string and then print out to a LED Matrix. So I cant seem to find much help on how to simply add "Woof" + "Bear" together into one string var?

Thanks in advance!
Hi,

I am new with the Arduino, but I have been playing a little with stepper motor control. In doing that I found the need for a string library. So I created one that emulates C++ std::string. Currently there are 2 arduino libraries needed for this (add them under hardware/libraries)
http://www.arnholm.org/arduino/ard_string.zip
http://www.arnholm.org/arduino/ard_new_delete.zip

With these, you can append one string to another etc.  smiley
9  Forum 2005-2010 (read only) / Troubleshooting / Re: disable auto-reset by serial connection on: April 19, 2008, 07:41:58 am
Quote
[quote author=cacb

I need to know where to put that code (i.e. I'm assuming it goes into the serial client program..... any chance of getting the full source code?)
 
Thanks again!

Yes, that code goes into the serial client program running on the PC. Below is a link to a couple of serial port C++ classes I have made for communicating over serial ports on Windows and Linux. That code includes the stuff I mentioned above.

http://arnholm.org/arduino/wxSerPort_20080519.zip

These classes are using the http://www.wxwidgets.org/ library. Essentially instantiate a serial port object using wxSerPort::construct(...) and use the set_hupcl member function to enable/disable "hang-up on close" with the Arduino.

10  Forum 2005-2010 (read only) / Troubleshooting / Re: disable auto-reset by serial connection on: April 18, 2008, 04:46:56 am
Quote
so this code will work with the usb diecimila? i have problem where the arduino is being powered via battery and when i plug in the usb to collect data from the sram the board resets and i loose all my data  smiley-sad

if not will removing those r2 and r3 on the board work. I would like to avoid this....
thanks

Yes it is the USB Diecimila. I have only been using it USB powered though. The code works for connecting several timed to the Diecimila over USB/Serial from the same or different PC program, without causing a board reset. I don't know if it would be a problem to power from battery and connect/disconnect USB cable like you say.
11  Forum 2005-2010 (read only) / Troubleshooting / Re: disable auto-reset by serial connection on: March 24, 2008, 07:52:37 pm
Hi,

I have researched this issue a bit on Linux and Windows. I have been able to get a client program (written in C++) to connect and disconnect to my Arduino Diecimila without causing a reset.

The solution lies in proper setup of the serial connection, and requires no extra hardware or hardware modification. You hust have to disable HUPCL on linux and DTR on Windows

On Linux you typically call tcsetattr
Before you call it you set

termios mode;
::memset(&mode,0,sizeof( mode));
tcgetattr(m_fd,& mode);
... other settings here
mode.c_cflag &= ~HUPCL;   // disable hang-up-on-close to avoid reset
tcsetattr(m_fd,TCSANOW,&mode)

On Windows

DCB dcb;
GetCommState(m_hCom, &dcb);
... other settings here
dcb.fDtrControl = DTR_CONTROL_DISABLE; // disable DTR to avoid reset
SetCommState(m_hCom, &dcb);
Then do NOT call EscapeCommFunction(...) or anything like that to set DTR later

With these settings I have it working for both Windows and Linux, I can connect as many times as I wish without causing a reset of the board.
Pages: [1]