ARDUINO - help and ideas thread

Yeah, as long as you’re not using usb tx/rx pins should work fine, but its much easier to use software serial, that way you can use serial monitor for debugging and quicker code changes turnaround.

Have you tried this code out yet? Looks like a good basis to start.

You probably know this but interrupts can only be added to pins 2/3 on an uno so you might want to change the servo pin to 9/10 so you can add other interrupts in future :grin:

Should probably ditch the delay in your main loop for millis() compare or an interrupt. Should prevent any problems later on

If I use software serial (let’s say I set pin 2 as rx and pin 3 as tx and name it “mySerial”), in the “VescUart.h” file – I’ll have to change “#define SERIALIO Serial”. What do I replace it with?

@domw95 The code as it is works but yeah i have to remove the delay and time the tasks. I actually just found this - https://learn.adafruit.com/multi-tasking-the-arduino-part-1/using-millis-for-timing after reading your post as it got me thinking. I got a good few hours on Saturday to start getting my head around this and tinkering. You are totally right about the pins and those will change as well. I was thinking about using the second channel for something but I’ll focus on the core first, extras later.

Thanks for the input

#define SERIALIO mySerial

1 Like

Cheers @EssEnn … il power up the netbook later and have a look, see if I can understand any of it. Currently making a stand for my PC PSU and accucell. Bit chilly and cloudy here today though, not sure I should charge my lipos just in case I don’t make it out! Actually found an app for android which allows you to open .Ino file and edit etc which saves me copying stuff to a .txt to mess with on my phone on the go

Reviving this thread I need some help. I am trying to work with two HC-05 modules and cant get them to work.

I am simply just trying to get an LED to turn on from a command on the master, repeatedly send a ‘1’ to turn on the LED. I just want to get the info sent over blutooth and adapt it later.

I have the two HC-05’s paired (blink together every 2 seconds) but I cant get the LED to turn on. Here is my code:

MASTER – int state; void setup(){ Serial.begin(9600); } void loop(){ if(Serial.available() > 0){ // Checks whether data is comming from the serial port state = Serial.read(); } Serial.write(‘1’); delay(1000); }

SLAVE –

#define ledPin 9 int state = 0;

void setup(){ display.begin(SSD1306_SWITCHCAPVCC, 0x3D); Serial.begin(9600); } void loop(){ if(Serial.available() > 0){ // Checks whether data is comming from the serial port state = Serial.read(); } if (state == ‘1’) { digitalWrite(ledPin, HIGH); // LED ON state = 0; } else if (state == ‘0’) { digitalWrite(ledPin, LOW); // LED ON state = 0; } }

Any help is greatly appreciated.

It looks like in the Slave code loop you are resetting state to 0 every time so the led turns off pretty much immediately the next time it gets to else if (state ==‘0’)

dom is right, you are not “keeping” the last state since you’re redefining it to 0 for every cpu cycle. Remove “int sate = 0;” and change “int sate;” to “int state = 0;”

Dont forget BT sends data, once, so it wont keep a 1 or 0 every time you read, just when you send that.

Something like this should do it. It does mean that to turn the led off you would have to send a 0 from the master, unless you put a timeout in the slave code to turn it off after not receving any more data.

void loop(){
  if(Serial.available()){ // Checks whether data is comming from the serial port
    state = Serial.read();
    
    if (state == ‘1’) {
      digitalWrite(ledPin, HIGH); // LED ON
    }
    else if (state == ‘0’) {
      digitalWrite(ledPin, LOW); // LED ON
    }
  }
}
1 Like

Still no luck… Any Ideas?

Slave

int ledPin = 12; int state;

void setup(){ display.begin(SSD1306_SWITCHCAPVCC, 0x3C); Serial.begin(9600); } void loop(){ if(Serial.available()){ // Checks whether data is comming from the serial port state = Serial.read();

if (state == '1') {
  digitalWrite(ledPin, HIGH); // LED ON
}
else if (state == '0') {
  digitalWrite(ledPin, LOW); // LED OFF
}

} }

Master

int state; void setup(){ Serial.begin(9600); } void loop(){ if(Serial.available() > 0){ // Checks whether data is comming from the serial port state = Serial.read(); } Serial.write(‘1’); delay(1000); Serial.write(‘0’); delay(1000); }

PS. I am not sure how to upload code, I tried pre formatted text but it only does some of it

@domw95 @chinzw

If you add 4 spaces in front off each line of your code it will format it like that :slight_smile:.

try putting:

pinMode(ledPin, OUTPUT)

in the setup for the slave.

Also you are defining state as an int but in the Master you are sending a char as ‘1’ or ‘0’. You are also checking for a ‘1’ or a ‘0’ char in the slave. Make sure the variable types are consistent.

For this it is probably easiest with char as then you are only sending a single byte.

I assume everything is wired correctly as you said you had the 2 modules paired?

I was about to reply the exact same thing. If you don’t set the pin as output, the pullup resistor will be enabled and it will limit a huge amount of current, so the LED might seem off.

Yes the modules blink together, I made a video but it was 90mb and I have DSL so that is not a good mix.

I will try the char and add the pin mode. Thanks a million for all of the help!

Side note, why isint anything coming up in the slave serial monitor? I just want to know how (make sure) that the data is being communicated. Both modules blink together roughly every 2 seconds and I have went over the wiring multiple times.

New Master Code: char state; void setup(){ Serial.begin(9600); } void loop(){ if(Serial.available() > 0){ // Checks whether data is comming from the serial port state = Serial.read(); } Serial.write(‘1’); delay(1000); Serial.write(‘0’); delay(1000); }

New Slave Code: int ledPin = 12; char state;

void setup(){ display.begin(SSD1306_SWITCHCAPVCC, 0x3C); Serial.begin(9600); pinMode(ledPin, OUTPUT) } void loop(){ if(Serial.available()){ // Checks whether data is comming from the serial port state = Serial.read();

if (state == '1') {
  digitalWrite(ledPin, HIGH); // LED ON
}
else if (state == '0') {
  digitalWrite(ledPin, LOW); // LED OFF
}

} }

I think you are going to need to use a Bluetooth Library to send the Serial commands to the module

Have a look through this tutorial it should help a lot http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-pair-bind-and-link/

If you are using the hardware serial (rx and tx pins) to communicate with the bluetooth module you cannot use the usb serial at the same time. They are the same thing so trying to send different data will mix it all up. If you want to use the serial monitor at the same time you will have to use Software Serial for the bluetooth.

Did you actually do anything to pair the modules?

Yes, I got the address and set one to master and slave using the AT commands. I thought that having it plugged into the computer will screw it up. I will check out the links and seperatly power both arduinos.

Edit: just tried powering from a separate supply. No bueno. I am using 2 HC-05’s so I will try it with an HC06. Thanks a lot for the pointers man.

No problem. I’m happy to blindly suggest solutions until it works :grin:

Currently working on an arduino sketch to read from a nunchuck thumb pot and generate a PWM signal, first wired but when my BT modules arrive, hopefully wireless. BTW the Nyko K I bought never worked… so parts will be used.

My vesc is dead so this is going to be for a HV ESC I got from an old helicopter that was sitting here while my DRV arrives from abroad.

Since there is little precision from the pot, I will implement something like cruise control, it will increase and decrease throttle smoothly and hold there when you let go.

Just got it working fine with a test motor and esc setup.

Maybe I’m reinventing the wheel… but this is something that will work with any ESC and can use the compact form factor of a Nunchuck.

Thoughts?

I like the cruise control idea. Probably worth using one of the rear buttons as a deadman switch that sends the ESC back to neutral when it is released otherwise things could go tits up

Going to need something similar on the receiver side that puts it in neutral if it doesnt receive a signal for a certain amount of time - already made that mistake and it wasnt good

Will everything fit inside the nunchuck ok?

I have nearly finished making my controller with a couple of nrf24l01 2.4ghz modules and Adafruit trinket pros (basically small Arduino Unos). Shall do a post when I get time.

1 Like