Show Posts
Pages: [1] 2
1  Development / Suggestions for the Arduino Project / Re: Interrupts for the Arduino Leonardo and clones on: March 13, 2012, 02:10:34 am
deleted, a bug in arscons made me think my mega wasn't working properly. it is.
2  Using Arduino / General Electronics / Re: Arduino and analogRead on: September 27, 2011, 02:28:04 pm
Quote
I tied analog pin 5 of my Duemilanove to the last resistor in the circuit; a voltmeter verifies that the voltage across the last resistor is 4.14V.

Your connections are not clear.  Any chance you can upload a diagram of how you have things connected?


Code:

                      +-------------+-+
                      |               |
                      |               |
                      |             +-++
                  +---+----+        |  |
                  |   +    |        |  |
                  |        |        |  | 2kOhm
                  |  12V   |        |  |
                  |   -    |        +-++
                  +---+----+          |
                      |             +-++
                      |             |  |
                      |             |  | 2kOhm
                      |             |  |
                      |             |  |
                      |             +-++          ARDUINO A5
                      |               +---------------------+
                      |             +-++
                      |             |  |
                      |             |  |  2kOhm
                      |             |  |
                      |             +-++
                      +---------------+

I'm measuring the voltage across the last resistor.

EDIT: I think I got it - had to connect the Arduino's ground to the negative battery terminal..
3  Using Arduino / General Electronics / Arduino and analogRead on: September 27, 2011, 02:10:17 pm
Hi all -

I'd like to use my Arduino as a basic voltmeter. I'm building a blimp and need to monitor the battery. I am using The MathWorks' ArduinoIO API, which essentially gives me the same functions as is naively available on the Arduino if I wrote in embedded C.

I have a 12V battery and using three 2kOhm resistors to build a voltage divider. I tied analog pin 5 of my Duemilanove to the last resistor in the circuit; a voltmeter verifies that the voltage across the last resistor is 4.14V.

I expected an analogRead() against that pin would give a reading of about 847, but this value is constantly jumping inside a range of 350 to 500.

Connecting the pin to AREF and trying an analogRead() gives me 1023, and connecting it to GND gives me 0, as expected.

So I'm not sure what's wrong with my circuit - am I missing something here? I thought this should be a pretty simple task..

Thanks for the help!
4  Using Arduino / Programming Questions / Arduino-MATLAB interface + Xbee? on: May 14, 2011, 02:29:31 pm
Hi all -

I wonder if anyone has experience using this Arduino-MATLAB API? http://www.arduino.cc/playground/Interfacing/Matlab

I am working in a research lab where most of our engineers are most familiar with MATLAB, and this API imports an Arduino class to directly drive the Arduino via MATLAB without need of creating/uploading a sketch to the chip itself.

Most of our experiments need to be done wirelessly - we equip our Arduino-powered vehicles with XBees and use an XBee connected to MATLAB to talk.

Does anyone know if it's possible to use this API wirelessly? I.e., instead of hooking up the Arduino directly to MATLAB for this driver, I'd like to hook up an XBee to MATLAB and an Xbee to Arduino, then use the API. I don't see why it wouldn't work, but I don't have access to my Arduino right now to try this out. I also wonder if there's latency issues I should worry about - right now I have a sort of XOR checksum to ensure the stuff I send from MATLAB to Arduino is received properly, and Arduino can request a retransmit if needed.
5  Using Arduino / Programming Questions / Re: Convert hex string to float - how? on: April 05, 2011, 02:38:21 am

Code:
//Converting a float to 4 bytes:
float float_var;
byte byte_array[4];

memcpy(byte_array,&float_var,4);

Save yourself some memory and copying...

Code:
union {
   //Converting a float to 4 bytes:
   float float_var;
   byte byte_array[4];
} both;

  both.float_var = 3.1415926535;

  send(both.byte_array[0]);  // or whatever it is you want to do with the bytes
  send(both.byte_array[1]);
  send(both.byte_array[2]);
  send(both.byte_array[3]);

This worked fine, although I ran into the endianness problem described above. I was receiving a hex string big-endian style and needed to flip to little-endian before the float was represented correctly.

Thanks to everyone for their help and insight on this!
6  Using Arduino / Programming Questions / Re: Convert hex string to float - how? on: March 31, 2011, 01:26:39 pm
Does the hex represent an IEEE754 float value?

Yessir. OP edited to denote that.
7  Using Arduino / Programming Questions / Convert hex string to float - how? on: March 31, 2011, 01:25:14 pm
Hi all -

My Arduino board will receive via Serial.read() a four-character hexadecimal string that I would like to convert into a float. The four character string is the IEEE754 representation of the float using four bytes.

I've looked all over the interwebs to figure out how to do this elegantly and I can't find anything - just how to convert a float to a string.

Can anyone help me? Thanks!
8  Using Arduino / Networking, Protocols, and Devices / Re: XBee on Blimpduino on: January 31, 2011, 02:02:53 pm
http://www.sparkfun.com/products/9132 is an XBee explorer that can hook directly onto the FDTI pins provided by Blimpduino.
9  Using Arduino / Networking, Protocols, and Devices / Re: XBee on Blimpduino on: January 30, 2011, 10:06:05 pm
I would post this question on the diydrones.com forums!

I tried that, I got pretty much zero response smiley-sad
10  Using Arduino / Networking, Protocols, and Devices / XBee on Blimpduino on: January 30, 2011, 08:17:20 pm
Anyone have experience interfacing XBee with Blimpduino? I've been scouring the internet and found a bunch of people who've done it, but give out no directions on how. Mostly I'm looking for what pins need to go where... Thanks for the help!
11  Forum 2005-2010 (read only) / Interfacing / Re: Help! XBee Series 2 can't do bidirectional comm on: January 19, 2011, 01:31:13 am
bump
12  Forum 2005-2010 (read only) / Interfacing / Help! XBee Series 2 can't do bidirectional comm on: January 18, 2011, 02:29:53 am
Hi all,

I've got an Arduino board with an XBee Pro Series 2 shield, and another XBee Pro 2 with a USB-to-serial adapter. I need to establish bidirectional communications between the two. The computer XBee is configured as Coordinator AT, and the Arduino XBee is configured as Router/End Device AT.

The Arduino has a sketch on board to toggle an LED on/off if it receives a "H" or "L" from the computer respectively. It also has a push button switch that performs a Serial.println("Hello world!") when you push it.

I am able to send data to the Arduino - i.e., use MATLAB to send "H" and "L" from my computer to the Arduino - but nothing happens trying to send the "Hello world" string from the Ardunio to the computer.

Can someone please help me configure the two XBees so RX/TX work both ways?

Thanks a lot!
13  Forum 2005-2010 (read only) / Interfacing / Re: XBee + MATLAB serial communications on: January 14, 2011, 03:40:20 am
For anyone interested - here is the code I wrote that lets you interface to your XBee device with MATLAB. It takes two inputs - your XBee device (s - assumed to be a serial devices that you've set up already) and a command in ASCII (command).

Code:

% XBCOMMAND - Write a command to an XBee device

function xbcommand(s, command)

    fprintf('\n');
    timeoutVal = 3; % Number of seconds to wait for data before killing the program
    
    if (~ regexp(s.Terminator,'CR')) % Reset the terminator to \r if needed.
        try
            fclose(s);
        end
    
        s.Terminator = 'CR';
        fopen(s);
    elseif (regexp(s.Status,'closed')) % if s wasn't open already, open it now.
        fopen(s);
    end
        
    % Write the user-specified command
    if (regexp(command, '\+\+\+'))
        fwrite(s, command);
    else
        fprintf(s, command);
    end
    
    % fetch, process and print result
    timeout = 0;
    while (timeout < timeoutVal)
        if (s.BytesAvailable > 0)
            timeout = 0;
            if (s.TransferStatus == 'idle')
                pause(0.01);
                q = fread(s, s.BytesAvailable, 'char');
                q = q';
                fprintf('%s\n', char(q));
                return;
            end
        end
        timeout = timeout + 1;
        pause(1);
    end
    
    error('Command timed out\n');

Hope this reduces someone else's pain and suffering. All I ask is you pay it forward if you use it - contribute to the general body of knowledge somehow!
14  Forum 2005-2010 (read only) / Interfacing / Re: XBee + MATLAB serial communications on: January 14, 2011, 02:28:19 am
Solved!

I don't know why the method of using fwrite() doesn't work when using a non-'+++' command. I was just playing around with the MATLAB command prompt. Here's what I did, with comments:

Code:
s = serial('/dev/ttyUSB0');
s.Terminator = 'CR'; % XBee expects the end of commands to be delineated by a carriage return.

fopen(s);

% Put the XBee in Command Mode
fwrite(s,'+++');
response = fread(s, s.BytesAvailable); % This will be a column vector of hex values - use the char() function to translate to ASCII, and transpose it if desired.

% Send an ATxx command

fprintf(s,'ATID'); % The \r is automagically sent out since we specified s.Terminator = 'CR'.

response = fread(s,s.BytesAvailable); % Result of the ATID command - again a column in hex, postprocess as desired.

I hope this helps anyone else out there who got stuck on this like I did. I am now able to send commands to XBee and receive them. My hope is to create a MATLAB serial terminal for XBee devices to simplify working with them.

EDIT: Hmm, I can't seem to replicate what I just did. I'm not sure why it's not working now. This seems silly. I'll keep posting with what I get.

EDIT2: It looks like the above works - apparently I'm hitting the timeout way too quickly and the XBee is exiting command mode much faster than I expected. I'll play around with it more.
15  Forum 2005-2010 (read only) / Interfacing / Re: XBee + MATLAB serial communications on: January 14, 2011, 01:37:02 am
I got it to work using fwrite() instead of fprintf() - I now get the 'OK' signal when I perform an fread().

But now I have a problem with sending commands to the XBee:

Code:
fwrite(s,'ATID\r');

I get no response from the module - s.BytesAvailable remains 0.

The Arduino IDE Serial Monitor yields the exact same behavior - I can input '+++' and get an 'OK' just fine, but nothing happens when I type "ATID\r". So it's not necessarily my MATLAB code - there is something going on with the serial communication itself.

However, using X-CTU with WINE (using Linux), I can connect to the XBee just fine and send commands with that serial terminal.

Any idea what is going on? Thanks!
Pages: [1] 2