GoBLE controller app code change.

Hi all.

Apologies for the total newbie question. We all have to start somewhere though?

I’m trying to update the Arduino code for the GoBLE Bluetooth controller app so that I can run it on a Pro Micro. My issue is that it all works fine when using an UNO but when I try to update the code to access Serial1 for the Micro I don’t get any readings on the serial monitor.

I’m pretty much just blindly trying things to see if they work. If anyone has the time to help me with this I would greatly appreciate it as I’m trying to make a Bluetooth controlled car with my boy.

I’m not asking for it to be done for me, I would like to know the reasoning and process to understand how to implement this and to further understand how to integrate Serial1 into existing code.

This is the test code for the app…

#include <Metro.h>
#include “GoBLE.h”

int joystickX, joystickY;
int buttonState[7];

void setup(){
Goble.begin();
Serial.begin(115200);
}

void loop() {
if(Goble.available()){
joystickX = Goble.readJoystickX();
joystickY = Goble.readJoystickY();

buttonState[SWITCH_UP] = Goble.readSwitchUp();
buttonState[SWITCH_DOWN] = Goble.readSwitchDown();
buttonState[SWITCH_LEFT] = Goble.readSwitchLeft();
buttonState[SWITCH_RIGHT] = Goble.readSwitchRight();
buttonState[SWITCH_SELECT] = Goble.readSwitchSelect();
buttonState[SWITCH_START] = Goble.readSwitchStart();

Serial.print("Joystick Value: “);
Serial.print(joystickX);
Serial.print(” ");
Serial.println(joystickY);

for (int i = 1; i < 7; i++) {
Serial.print("Button ID: “);
Serial.print(i);
Serial.print(”\t State: ");
if (buttonState == PRESSED) Serial.println(“Pressed!”);
_ if (buttonState == RELEASED) Serial.println(“Released!”);_
* }*

* }*
}
I’ve tried adding Serial1.begin (115200) to the setup and If (Serial1.available()) to the loop before the If (Goble.available()) command. This made the information scroll in the serial monitor when I pushed any button on the app but the values didn’t change, they all remained at their defaults.
I have managed to get Hex readings in cooltemp after writing a basic Serial1.print sketch. That confirmed I have the hardware hooked up and configured correctly. I just need to figure out how to modify the code.
Again, thank you for your patience as I’m sure this is an obvious thing to experienced programmers but it’s escaping me and I can’t seem to find any advice for this in searching forums/google.

Since you don't specify pin numbers for the Goble instance, one can only assume that the Goble class knows far better than you do, where the BLE device is connected.

If that arrogance offends you (and it would piss me off royally), use a different library, or modify the one you are using.

Hi Paul.

Yeah, I get the impression the little monkey is laughing at me.
In using the UNO I didn't have to define the pins and it worked using the apparent power of magic.

I'm using an HM-10 hooked up to pins 0 and 1. The difference being on the Pro Micro pins 0 and 1 are treated as serial 1 and not just serial as on the UNO.

My question is how to modify either the code and/or library to adjust for the information coming from Serial1 as opposed to Serial.

Glaring holes in my knowledge will be very apparent I'm sure.

Cheers
M

The difference between the UNO and Pro Micro is that the serial pins are reversed. On UNO it's 0 for RX and 1 for TX, on Pro Micro pin 0 is TX and 1 is RX. If you swap the HM-10 wires it should work.

Cheers! Yes, they're connected the right way as it works fine with other sketches. This is about modifying code to respond to Serial1 as opposed to the default Serial.

It's always good to check the obvious though.

Yes, sorry. Look for the file GoBLE.cpp in your libraries folder (referenced on Github) and try changing all references of "Serial" to "Serial1".

Cool. I hadn’t looked at the .cpp file. I’d looked in the .h file but there wasn’t any reference to Serial in there. Does the .cpp file get included when you include the .h file? (I can google this if it’s easier)

What’s the best way to edit the .cpp? I’m on a Mac. Is Text Editor the way forward?

I’ll give this a go

Many thanks

Does the .cpp file get included when you include the .h file?

No. But it does get copied to the build directory and does get compiled.

What's the best way to edit the .cpp?

With a text editor. 8)

Is Text Editor the way forward?

It's A way forward.

Thank you! That worked perfectly!

PaulS:
No. But it does get copied to the build directory and does get compiled.
With a text editor. 8)
It's A way forward.

Thank you! That's good to know. I've got it working now by modifying the .cpp file. Every day is a school day!

I appreciate both yourself and Blue Eyes taking the time to help me out. It'll certainly put a smile on my boy's face.

Cheers!