Hi
This is my first post here on the arduino forum so go easy on me please.
I have started a quadrocopter project with the intention of learning alot of embedded systems such as microcontrollers and different mechanical actuators. The goal of the project is to in the end make it fly autonomous outdoor with a mounted camera to film the ride. This is a project i plan on doing for many months forward and still in the beginning of the project.
The problem:
The problem is that i would like to communicate with the IMU card using the hardware serial pins on the Nano (RX0 and TX1). Which for some reason does not work as i expected (will come to that later just so you have an idea of what im doing)
I have the following components:
- IMU (9dof) - flashed with Razor AHRS
- Levelshifter from 3.3v to 5v
- Arduino Nano
- Arduino Uno
- FTDI 5v cable
The levelshifter is created by me using this scheme Sparkfun level converter. It is a 50% voltage cut on the TX side and a transistor boost on the RX side.
The code that i have flashed into the IMU is taking different commands so i can manipulate the output from it. On the IMU there is also a LED that is on if the IMU is in continious sending mode and off otherwise.
The different commands i am trying to send to the IMU is
- #o0 //This stops continuous output from the IMU
- #o1 //This starts continuous output from the IMU
By sending those commands one after eachother i can make the IMU blink (if i do it with some delay in between). But here is where i get into problems. When using the code below the IMU does blink perfectly when i put the RX pin from IMU card to pin 9 (Soft transmit pin), but when i change it to the hardware pin (TX1) it does not work as expected. The wierdest part is that it works "sometimes" say 1/50 times it actually changes value, i checked this by just increasing the frequency i changed the value with to like 10hz instead of 1hz and count seconds between diode on and off by observing myself.
Code put into the Nano
#include <AltSoftSerial.h>
#include <HardwareSerial.h>
// AltSoftSerial always uses these pins:
//
// Board Transmit Receive PWM Unusable
// ----- -------- ------- ------------
// Arduino Uno 9 8 10
AltSoftSerial altSerial;
unsigned long time=0;
boolean p=true;
void setup() {
Serial.begin(57600);
altSerial.begin(57600);
}
void loop() {
//change value every 1 second
if(time<millis()){
time=millis()+1000;
if(p){
p=false;
altSerial.write("#o0");
Serial.write("#o0");
}else{
p=true;
altSerial.write("#o1");
Serial.write("#o1");
}
}
}
Other experiments i have done
-
I have used a FTDI 5v cable connected to the IMU by the level converter. Then everything works just fine. When i write "#o0" and diode turns off and when i write "#o1" the diode turns on.
-
Connected an Arduino UNO in paralell to the TX1 pin of the Nano (Nano --> Uno+IMU), and then read it directly using the console to confirm that the Nano actually sends correct serial information. Here on the IMU i get same behaviour sometimes it works(1/50), but on the Uno i get correct value all the time.
"Question"
Why does the hardware pins behave like this? Is there some trick to serial communications using hardware pins? Is this a problem with signal levels (5v, 2.5v)?
//Regards KufrA