First I am not sure if I am placing this in the right area if not I am sorry. I have been going crazy playing with my UNO (ya ya I know play with it too much and you will go cross eyed) but it’s so much fun. I am an electronics Engineer not a programmer so my programing skills stink but I get all my projects to work. I am working on a 4 wheel drive bot with Bluetooth control. My issue is it works great on the UNO but refuses to work on the Micro. I got bits and pieces of programs from the web and stitched them together and then slowly cleaned it up till it worked. My issue is the Bluetooth only wants to work on certain pins of the Micro but works on any pin on the Uno and I have no idea why. I tested each pin on the Micro one at a time for input then output and all the pins are fine so it’s not a bad unit. On the Uno I was using serial pins 0 and 1 Rx and Tx worked great on the Micro if I use them I only can receive from Bluetooth not send to Bluetooth. It only wants to work on pins 13,12,11,10,9,6 and 13 and I don’t know why it’s a serial ttl signal not a pwm signal. Any thoughts would be greatly appreciated. The net part is the sketch I have like I said I got bits and pieces from all sorts of programs and stitched them together but there is a few lines in there that I have no idea what they do but if removed the program fails to run. Please look at the lines marked with I have no idea and tell me your input on them if you can. Use what ever you want of it. Thanks in advance for any help..
//This version has 2 way comunications and has full foward right left stop and back..
#include <SoftwareSerial.h> //Software Serial Port
int RxD = 11; // Tx from Bluetooth to pin11 Arduino VIOLET WIRE
int TxD = 2; // Rx from Bluetooth to pin 2 Arduino GRAY WIRE
int PINLED = 13; // Uses pin 13's led to test if device working.
int pinI1 = 8; // define I1 interface BROWN WIRE
int pinI2 = 4; // define I2 interface YELLO WIRE
int pinI3 = 6; // define I3 interface GREEN WIRE
int pinI4 = 7; // define I4 interface BLUE WIRE
int lpwm1 = 9; // pwm left
int rpwm1 = 10; // pwm right
int lpwm = 30; // sets lpwm counter start at 30
int rpwm = 30; // sets rpwm counter start at 30
#define DEBUG_ENABLED 1 // [color=red]I have no idea.[/color]
SoftwareSerial blueToothSerial(RxD,TxD); // I thinks its assigning RxD and Txd data to blueToothSerial
void setup()
{
Serial.begin(9600); // sets data rate for Serial Monitor
pinMode(RxD, INPUT); // sets RxD as a input
pinMode(TxD, OUTPUT); // sets TxD as a output
pinMode(PINLED, OUTPUT); // sets PINLED as a output
pinMode(pinI4, OUTPUT); // sets pinI4 as a output
pinMode(pinI3, OUTPUT); // sets pinI3 as a output
pinMode(pinI2, OUTPUT); // sets pinI2 as a output
pinMode(pinI1, OUTPUT); // sets pinI1 as a output
pinMode(rpwm1, OUTPUT); // sets rpwm2 as a output
pinMode(lpwm1, OUTPUT); // sets lpwm2 as a output
setupBlueToothConnection(); [color=red]// I have no idea.[/color]
}
void loop()
{
char recvChar;
while(1)
{
{
if(Serial.available()) //check if there's any data sent from terminal
{
recvChar = Serial.read();
blueToothSerial.println(recvChar); // Sends data typed on terminal to bluetooth unit.
}
}
if(blueToothSerial.available()) //check if there's any data sent from the remote bluetooth shield
{
recvChar = blueToothSerial.read();
Serial.print(recvChar);
if(recvChar == 'f') // Forward
{
lpwm = lpwm+10;
rpwm = rpwm+10;
analogWrite(lpwm1,lpwm); // lpwm on
analogWrite(rpwm1,rpwm); // rpwm on
digitalWrite(pinI4,HIGH); // turn DC Motor B move clockwise
digitalWrite(pinI3, LOW); // turn DC Motor B move clockwise
digitalWrite(pinI2,HIGH); // turn DC Motor A move clockwise
digitalWrite(pinI1,LOW); // turn DC Motor A move clockwise
}
else if(recvChar == 's') // all stop
{
analogWrite(lpwm1,LOW); // lpwm off
analogWrite(rpwm1,LOW); // rpwm off
digitalWrite(pinI4,LOW); // all stop
digitalWrite(pinI3,LOW); // all stop
digitalWrite(pinI2,LOW); // all stop
digitalWrite(pinI1,LOW); // all stop
digitalWrite(PINLED,LOW); // all stop
lpwm = 10; //re-sets lpwm start at 10
rpwm = 10; //re-sets rpwm start at 10
}
else if (recvChar == 'l') // left
{
lpwm = lpwm+10; // sets start of lpwm at 10 increases by 20 each press.
rpwm = rpwm+10; // sets start of rpwm at 10 increases by 20 each press.
analogWrite(lpwm1, lpwm); // lpwm out
analogWrite(rpwm1, rpwm); // rpwm out
digitalWrite(pinI4,HIGH); //turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW); //turn DC Motor A move clockwise
digitalWrite(pinI1,HIGH);
}
else if(recvChar == 'r') // right
{
rpwm = rpwm+10; // sets start of rpwm at 10 increases by 10 each press.
lpwm = lpwm+10;
analogWrite(rpwm1, rpwm);
analogWrite(lpwm1, lpwm);
digitalWrite(pinI4,LOW);
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,HIGH);
digitalWrite(pinI1,LOW);
}
else if(recvChar == 'b') // back up
{
lpwm = lpwm+10;
rpwm = rpwm+10;
analogWrite(rpwm1, rpwm);
analogWrite(lpwm1,lpwm);
digitalWrite(pinI4,LOW);
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,LOW);
digitalWrite(pinI1,HIGH);
}
else if(recvChar == 't') // Test bluetooth control led on 13 will light if t pressed
{
digitalWrite(PINLED, HIGH);
}
}
}}
void setupBlueToothConnection()
{
blueToothSerial.begin(9600); // Set BluetoothBee BaudRate to default baud rate 9600
//blueToothSerial.print("\r\n+STWMOD=0\r\n"); // set the bluetooth work in slave mode
//blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); // set the bluetooth name as "SeeedBTSlave"
//blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
//blueToothSerial.print("\r\n+STAUTO=1\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); // make the slave bluetooth inquirable
//Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}