Show Posts
Pages: [1] 2 3
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Arduino Serial Monitor and C++ stand along app reading serial print on: March 04, 2013, 03:51:54 pm
I've been able to connect to and get the Serial data from the Arduino. When I use, in my Ubuntu terminal, cu -l /dev/ttyUSB0 it prints the information correctly. When I run my c++ program no matter how I have managed to control the USB settings in the termios struct I get a whole mess of gibberish trying to print chars to the screen using something like:

cout << data << endl;
(In a for loop)
cout << (char)data;
cout << data;
printf("%s", data);
printf("%c", data);

I'm getting the same junk/gibberish chars. I guess it could be possible to have it run, write to a file then read that file but reading and writing at the same time would call for much greater difficulty requiring mutex locks to make sure I don't run into the end of the file.

I will paste the code I am using below if you care to have a look see:

#include <iostream>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <stdio.h>
using namespace std;

#define bufferSize 100

int open_port(void)
    int fd;

    fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY| O_NDELAY);

    if (fd == -1)
        // Could not open port so send error
        perror("open_port: Unable to open /dev/ttyS0 - ");
        // port is open and connected to fd
        fcntl(fd, F_SETFL, 0); // if don't want to block use FNDELAY
        return (fd);

    return (fd);

int set_port(int fd)
    struct termios options;
    tcgetattr(fd, &options);            // get current options for port

    cfsetispeed(&options, B9600);        // set input baud rate
    cfsetospeed(&options, B9600);        // set output baud rate
    options.c_cflag |= (CLOCAL | CREAD); // enable receiver and set local mode

    // No parity and 8 bit char definition with 1 stop bit
    options.c_cflag &= ~PARENB;
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS8;

//    options.c_cflag &= ~CRTSCTS;         // Turn off flow of hardware control

    return tcsetattr(fd, TCSANOW, &options);

int main() {

unsigned char data[bufferSize];

int fd = open_port();

while (read(fd, &data[0], sizeof(data)) != -1)
//     cout << data << endl; // this prints the same gibberish as the for loop print statement.

    int lastCheck = sizeof(data);
    int i = 0;

    for (i = 0; i < lastCheck; i++)
      cout << data[i];

if (read(fd, &data[0], sizeof(data)) == -1)
    cout << "Reached end of USB read" << endl;

return 0;
2  Using Arduino / Interfacing w/ Software on the Computer / Re: Explaing tabs on attached pic of Arduino program on: March 04, 2013, 03:32:56 pm
The Sensor tab probably refers to another file in your project. If you open your project folder you should see a file named Sensors."some extension, pde, ino, c, h, what have you". This file is probably included in some way into your main project or part of another file. It is likely being used to control sensor data of some sort.
3  Using Arduino / Interfacing w/ Software on the Computer / Arduino Serial Monitor and C++ stand along app reading serial print on: March 04, 2013, 01:15:31 pm
I've looked around for a few days and have come up empty in trying to find an example or explanation to answer my questions:

I am writing a C++ application that will read the serial print data from my Arduino. My program will then parse that data and run a simulator from the parsed commands. I have successfully been able to read the serial data from the USB port but only when I click on the Serial Monitor icon when I open the Arduino software.

I would like to know what is being sent to the Arduino so that it will reset and begin the Serial print.

I would also like some pointers as to which options I need to set with my program for the USB port. I am getting some strange characters on the print from the Arduino instead of just plain text. I thought it would probably be something that I set wrong in the settings in the termios structure.

The idea I am building is, due to a failure to make my drone fly with the communication I have been able to send over WiFi, that I will build a simulator to show that the program I wrote for my Arduino functions as described. So for this application I decided it would be easiest, and probably best displayed, using the Arduino board to run the program with the sensors attached to it and feeding all the commands that were to be sent to the drone through Serial.println statements. Then parsing those statements and having a graphical representation built in QT with C++ in Ubuntu display tilt, rotation, and flight direction. Ideally this will run on my laptop as a stand along application so I don't have to boot up the Arduino IDE and start the serial monitor from there, although I won't get too particular about it since I only have about 2 weeks, with about an hour or 2 a day at most, to devote to this before I hit the deadline!

Any help or direction is appreciated,
4  Using Arduino / General Electronics / Re: Power Issues creating sensor read issues on: February 18, 2013, 03:49:47 pm
Hi Tom,

Thank you for your information and follow up on this problem. I was able to make the sensors work, I had to recalculate the formulas in my sketch but they are functioning now. I am taking 1 reading every 100 milliseconds and every third read I only use the largest value of the three and take three more readings. This, while slow, gives me good information to go on.

The problem I had was a "misprint" on LinkSprites RedBack board. It only has 3v output, but when you use USB to power it the 5v output pin does output 5v. But powering the board through the regulated RAW pin cuts power down to 3v on all output pins. To solve the issue I attempted to use a 5v regulated power supply and the USB VCC and Ground pins. This blew the board when the spec sheet says that this is supported. I had to order another RedBack board from LinkSprite, not sure what to do about the broken one..
5  Using Arduino / General Electronics / Re: Power Issues creating sensor read issues on: January 29, 2013, 04:32:18 pm
I talked to linksprite tech support about my problems and they tested the boards that they had in stock. They said that the silk screen has a print error and there is no 5v output on the RedBack, only 3v. However when using the FTDI breakout to power the board it does do 5v output.

Hopefully posting this here will help others that might be using this board. When my replacement shows up I will test the output voltages on both the 3 and 5v output pins using the RAW input power pin and the FTDI power.

Thanks for all the help!
6  Using Arduino / General Electronics / Re: Power Issues creating sensor read issues on: January 27, 2013, 04:44:29 pm
Running 3 maxbotix range finders:

I plugged the regulated 5v supply into the vcc pin and ground to the vcc ground, the redback isn't working anymore. So apparently that won't do the trick for me. I'm getting lights but it's not doing anything program wise, it's not starting the WiFi and no print statements are running through the initial setup function over the serial port.

I have to present this project on Tuesday so I think if I order a next day air today would it show up Monday (just guesstimates or do I have to wait till Tuesday at 4pm (when UPS normally comes through my area) if I order next day air on Sunday afternoon. Not that it matters much if the power problem is something I'm doing wrong and wasn't the board then I will still have the same problem with a new one....

I'm pretty sure it's the WiFi module that's cooked on this board, everything runs until I try to initialize and run anything through the WiFi module. It was working before I tried the vcc power and immediately after it stopped so just by process of elimination....

Anyhow suggestions on how to save this thing possibly?
7  Using Arduino / General Electronics / Re: Power Issues creating sensor read issues on: January 27, 2013, 03:28:45 pm
The redback input power pin is called RAW and it is connected directly to an onboard 5v voltage regulator and from there to the 5v output pin. When I connect a 7.4v battery to the RAW pin the 5v output pin on the redback is only putting out 3.2v.

I wired together a 5v voltage regulator with capacitors to filter the output so it stays at a steady 5.02v. When I put this into the RAW input pin the 5v output pin on the redback is only doing 3.2v.

In every scenario the 3v output pin is pushing 3v.

My understanding of the architecture of the redback is that the onboard 3v voltage regulator is put in line between the 5v regulator and the 3v output pin. However the power levels I am reading on the 5v output would seem to suggest that there is an issue with the setup on the redback.

When I run the redback from the FTDI USB cable that has the 6 USB header pins the 5v output pin pushes 4.6v which is what the power readings show when I measure the VCC and ground on the USB header while I have it plugged into my laptop. Since the VCC pin is wired to the 5v output I thought I would ask if I am going to burn anything by wiring my regulated 5v supply to the VCC pin. The VCC pin is also connected to the TTL parts on the board, for serial communication. If I only wire 5v to vcc and ground on the same header I would think everything should be fine. I'm basically looking for somebody with more knowledge than myself to affirm this guess if it's possible.

Thanks oric_dan!
8  Using Arduino / General Electronics / Power Issues creating sensor read issues on: January 27, 2013, 02:10:24 pm
I was having a power issue and when I run anything through the on-board voltage regulator (on a linksprite redback), either filtered 5v using a voltage regulator and capacitors before connecting to the redback, or 7.4v unregulated connected directly to the redback it is knocking the power to the 5v output pin to ~3.03v. The range finders I am running are based on a 5v set up.

When I run the board through the USB cable I have no problem with the sensors.
Can I put regulated 5v power on the USB VCC input pin and ground on the USB header?
Would doing this solve my problem as well?
I tested voltages with the USB cable connected and it is doing just over 4.6v, would connecting 5.02v be a problem?

I haven't tried simply because I already burnt out a ~$60 board and had to replace it with ~$80 and I don't want to have to spend more money on credit to finish this project HAHA!

This is a picture, the redback is a copy of the asynclabs yellowjacket. I can see the lines from the VCC go to the 5v output pin, but it also goes to the ttl converter, would that create a problem?

Thanks for any help,
9  Using Arduino / General Electronics / Software guy needs help with circuit on: January 16, 2013, 08:35:30 pm
My project has an 11.1V 800maH battery.

I would like to use this to power my RedBack ( ) and three Maxbotix ultra sonic range finders ( ).

I understand that Ohm's law is v = ir however I don't know how to apply this to my problem.

I would like to keep the power range going into the Redback between 5-7v. I don' t know minimum power requirement for maH in this type of set up. I tried using another battery for this project but it is just way too heavy so I need to build a circuit that will go from the 11.1v 800maH battery and drop it's power down. I would really appreciate some help with either numbers to calculate this or just a few links to hardware that would do the trick.

Thank you in advance,
10  Using Arduino / Sensors / Re: Extreme data variation with MaxBotix Ultrasonic Rangefinder on: January 10, 2013, 02:22:04 pm
If I buy a set of the MB1242 sensors can I use the same wiring scheme that I have now? I have good insulated wire so noise isn't an issue and I am powering the sensors and arduino from a power source separate from the drone. A good lipo battery should be providing sufficient power for everything, 7.4V, 800maH.

As I have it now I can make the project work but if I decide to spend a whole mess of money getting more sensors I want to be sure I won't have to rebuild everything.

11  Using Arduino / Sensors / Re: Extreme data variation with MaxBotix Ultrasonic Rangefinder on: January 05, 2013, 07:35:01 pm
I was reading with every loop and dialed it back to 100 milliseconds and doing the largest of 3 readings from that. So I'm getting one solid read roughly every 300-325 milliseconds. I'm not sure if that is fast enough. Although, I am getting better data. I'm worried it might be running into a wall before any decision could be made, unless I tell it to stop from 10' away lol. Hopefully that's the worst case scenario haha!

Would you wage a guess that if this was on a quad copter the flight speed would be seriously hampered by a bottle neck that large? All flight control decisions are based on this sensor data.

I'm working on getting interference with rotor noise worked out then hopefully moving onto actual flight. I have most of the program wrote for an initial text but I have this issue and the interference issue to figure out. I have some ideas on the interference problem but I may be back here asking for advice on that.

Thank you,
12  Using Arduino / Sensors / Re: Extreme data variation with MaxBotix Ultrasonic Rangefinder on: January 05, 2013, 05:03:45 pm
I read the link, that is why I am using the mode in a lower section that is titled:
Sequentially Read Each MaxSonar
which is followed by (Always Works)

I tried getting 3 readings and only using the maximum value of the 3 and I am still getting greater than 12 inches of variation on that one sensor.

Does anybody have experience trying to use multiple sensors on the same project? My next idea at this point is to re-wire and use the section titled:
Control the MaxSonar Sensors to Range Simultaneously
I chose not to use this one because it explicitly says that this works for most, and not all situations.

Could I just have a bad sensor?

13  Using Arduino / Sensors / Extreme data variation with MaxBotix Ultrasonic Rangefinder on: January 05, 2013, 02:05:33 pm
I am using three MaxBotix ultrasonic range finders:

using the Sequentially Read Each MaxSonar wiring scheme:

I have played with angles and surfaces they are pointed at, a timer around the calling function so there is a time lag between each of the analogRead functions and I am still getting a very large range in data collected from the lead sensor in the chain. This latest run I was getting from 16 inches to 57 inches (variation of 41 inches is not going to work for my application), and the second sensor has a 10 inch variation and the final sensor only has a variation of 4 inches.

Am I doing the wrong kind of scheme? Would the Continuous looping scheme give me more accurate readings? Are there any other suggestions?

Should I try using a filter to and try to get an average before making decisions about actions? That idea comes up because the high values seem to be accurate and the pattern might work if I take 3 readings and if one of the 3 is higher than my threshold then continue normally or if all is less than stop the aircraft.

Thanks for any help,
14  Using Arduino / Programming Questions / Re: Time between button press on: December 25, 2012, 11:00:04 am
If I understand your question right, this might do the trick. I just added some code to your loop.
I didn't run this, there could be a bug or a problem with my logic, however something like this
might steer you in the direction you're looking to go:

int inPin = 2;         // the number of the input pin
int outPin = 13;       // the number of the output pin

int state = LOW;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers
long dur_on = 0;    //the duration between ON/OFF

void setup()
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);

void loop()
reading = digitalRead(inPin);

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce)
time = millis();

if (state == HIGH)
state = LOW;
state = HIGH;

// if the input is high then remember the time and print duration
// else ignore time reading and continue with loop
if ((reading == HIGH) && (millis() - time > debounce))
dur_on = (millis() - time)/1000;

digitalWrite(outPin, state);

previous = reading;
15  Using Arduino / General Electronics / Re: Program Not running from alternate power supply on: December 23, 2012, 03:36:34 pm
Thank you James, I misunderstood your earlier statement.

Do you think if I just wire a voltage regulator from power supply to the board that would be sufficient in this case?
Do you think this guy would clean up everything if i just wire input and ground to battery and output to the input pin?

This is a diagram as I have been wiring it for actual use if it will help at this point:

I went and bought a 7.4v 800mA lipo battery. I still have to charge it but hopefully in the morning I will be able to test this.
Pages: [1] 2 3