Problems with serial communication

Questions and Discussion concerning the Bare Bones Board
Post Reply
grinan
Posts: 4
Joined: Mon Jun 16, 2008 10:20 pm

Problems with serial communication

Post by grinan » Fri Jun 20, 2008 8:37 am

Hi, I recently purchased the BBB from moderndevice, and am having problems with serial communication.

I may be confused in my thinkings, but I thought that the BBB had the software reset on it, which would mean (in my thinking) that i would not have to push the reset button each time i wanted to upload new code to the BBB. That's not happening in my case. Each time I try to upload I get an error message. I finally figured out that if i push the upload button in the software, wait for a 2 count, push the reset on the BBB and hold it for a 3 count, the sketch will upload almost everytime.

That's a pain, but i could deal with it...

Then, when working with a parallax Ping))) unit, I realized that i have no serial communication between the BBB and my pc when i run a sketch. I tried a few things like adjusting my com port, and my baud rates, but, i thought that they would have already been set by the fact that i can actually upload a sketch.

The tutorial/code I was working with :
http://www.arduino.cc/en/Tutorial/UltrasoundSensor

I readjusted the code several times.. to no avail. I thought that maybe the ping unit was bad.. so i broke out the old basic stamp, 4 minutes later, i was pinging to beat hell.. with accurate measurements.

I know that if the BS2 is capable of using the ping, the BBB or aduino in general should be able to as well.

Can anyone offer advice? Any help would be appreciated.

grinan
Posts: 4
Joined: Mon Jun 16, 2008 10:20 pm

Re: Problems with serial communication

Post by grinan » Fri Jun 20, 2008 9:27 am

Well, apparently having a good nights sleep does make a difference.

The code below, WHEN WIRED CORRECTLY does work.. and low and behold, you will have serial capabilities!! (duhh)

Code: Select all

/* Ultrasound Sensor
 *------------------
 *
 * Reads values (00014-01199) from an ultrasound sensor (3m sensor)
 * and writes the values to the serialport.
 *
 * http://www.xlab.se | http://www.0j0.org
 * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
 *
 */

int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13

void setup() {
  beginSerial(9600);                  // Sets the baud rate to 9600
  pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
}

void loop() {
 timecount = 0;
 val = 0;
 pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

/* Send low-high-low pulse to activate the trigger pulse of the sensor
 * -------------------------------------------------------------------
 */

digitalWrite(ultraSoundSignal, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignal, LOW); // Holdoff

/* Listening for echo pulse
 * -------------------------------------------------------------------
 */

pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
val = digitalRead(ultraSoundSignal); // Append signal value to val
while(val == LOW) { // Loop until pin reads a high value
  val = digitalRead(ultraSoundSignal);
}

while(val == HIGH) { // Loop until pin reads a high value
  val = digitalRead(ultraSoundSignal);
  timecount = timecount +1;            // Count echo pulse time
}

/* Writing out values to the serial port
 * -------------------------------------------------------------------
 */

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

serialWrite('A'); // Example identifier for the sensor
printInteger(ultrasoundValue);
serialWrite(10);
serialWrite(13);

/* Lite up LED if any value is passed by the echo pulse
 * -------------------------------------------------------------------
 */

if(timecount > 0){
  digitalWrite(ledPin, HIGH);
}

/* Delay of program
 * -------------------------------------------------------------------
 */

delay(100);
} 
you should place an LED between pin 13 and ground.

Ping))) unit should have SIG to pin 7, and GND and + to ground and +5 respectively.

You can see measurements in the serial monitor.

I have not yet messed with the code much, but if there is interest in this, i will expand the code to add servo or motor control to integrate it into a bot.

paul
Site Admin
Posts: 733
Joined: Mon May 12, 2008 4:19 pm

Re: Problems with serial communication

Post by paul » Sun Jun 22, 2008 12:09 am

Thanks for the post grinan,

Is this for a Parallax Ping? There are five or six of thess sonar sensors out there, they all work in a similar fashion but the interface (& coding) details are slightly different. They are optimized in different ways too. The Ping sensor, for example, sees walls well, but is less useful for sensing people, I think the clothing doesn't give a clean enough return for its gain settings.

I also think that printInteger is deprecated and Serial.print() is currently preferred coding, just as a suggestion. It still works fine though, but may not at some point.
Serial.println() adds the CR & LF automatically so is handy to save a couple lines of code.

Paul

grinan
Posts: 4
Joined: Mon Jun 16, 2008 10:20 pm

Re: Problems with serial communication

Post by grinan » Sun Jun 22, 2008 1:26 am

This is a parallax ping unit. It was more accessible to me since radio sha** now carries some parallax stuff.

I have not noticed many issues with the ping so far.. as i got my coding worked out.

What i am researching now is the dc motor control via a sn755410 h-bridge, and pwm. Needless to say, the results are not what i had hoped for.

Still working on it though.

Thanks for the tip about Serial.print().. Still learning all the arduino code... much different from the pbasic i was dealing with.

grinan
Posts: 4
Joined: Mon Jun 16, 2008 10:20 pm

Re: Problems with serial communication

Post by grinan » Sun Jun 22, 2008 1:29 am

Ok.. paul, you seem to know a bit about the arduino ( duhh.. )

What's the deal with pwm.. I seem to be able to control one motor with zero problems.. but can't control two at the same time.

Is this a limitation of the arduino? Can't send to pwm signals at once?

just wondering..

dufarb
Posts: 5
Joined: Tue Jul 08, 2008 7:50 pm

Re: Problems with serial communication

Post by dufarb » Tue Jul 08, 2008 8:07 pm

Hello,
I am having the an issue uploading to the board. It requires a button press to upload. The board selection that works is Arduino NG or older w/ ATMega168. I assumed that it would work with the Diecimila settings, but I could not get it to upload. Any ideas on what I am doing wrong?
Thanks,

mlctrez
Posts: 5
Joined: Mon Jun 23, 2008 4:03 pm

Re: Problems with serial communication

Post by mlctrez » Wed Jul 09, 2008 6:30 pm

dufarb -

Can you give a bit more information on the type of serial/USB cable between the computer and the BBB and the operating system you are using?

I had a similar problem with using the FTDI USB cable and Linux which was resolved with some updates to the RxTx library.

- Matt

paul
Site Admin
Posts: 733
Joined: Mon May 12, 2008 4:19 pm

Re: Problems with serial communication

Post by paul » Sat Jul 12, 2008 12:57 am

dufarb,

Give me some details about your platform and OS.

If you're using Windows check this

Device Manager -> Com Ports -> USB Serial Port -> Port Settings -> Advanced button -> Set RTS On Close

The Arduino IDE setting should be Diecimila, as all my current products are provided with Diecimila bootloaders, unless customers ask for Adaboot.

Paul

paul
Site Admin
Posts: 733
Joined: Mon May 12, 2008 4:19 pm

Re: Problems with serial communication

Post by paul » Sat Jul 12, 2008 1:12 am

grinan,

This forum topic seems to be going in several directions. Starting new topics for different questions is a good idea in the future.

It's hard to say what's going on with your pwm - The Arduino will definitely support 6 channels of PWM. There is a noted bug in pin 5 and 6 pwm which conflicts with calls to millis(), so you may wish to avoid pins 5 & 6 for a start.

Your hardware setup maybe an issue too, when people add another motor and things start braking, I always ask about the power supply. Especially if you are trying to power two motors through the voltage regulator on the BBB, you may just be having issues with not enough current able to be provided by the voltage regulator on the BBB. One solution is to use an external 5 or 6 volt REGULATED supply, and power the motors (interfaced with a power transistor or MOSFET) through the power rail pins on the BBB. Set the PRJ (power rail jack) shunt to the EXT (external) position. That will route the regulated power adapter's output directly to the power rails.

Let me know about your hardware setup and then post some code and I'll try to help you.

Paul

dufarb
Posts: 5
Joined: Tue Jul 08, 2008 7:50 pm

Re: Problems with serial communication

Post by dufarb » Thu Jul 24, 2008 3:29 pm

Paul and mlctrez,

Unfortunately I purchased the BBB from another site and can not be sure what bootloader is on the chip. I will try out another chip that I just purchased here. Thank You both,

Post Reply