[Solved] Issue with Bluz DK in Serial1 debugging


I am trying to debug my sketch flashed into Bluz DK. I have gone thru’ the Serial Debugging tutorial.
I am using a photon as the USB serial adapter. Only TX-RX pins are connected accordingly between Bluz and Photon since I am powering the Bluz from a separate power source.

Now after I flash my new code having Serial1.begin(); Serial1.print() etc., the Bluz doesn’t work properly - it keeps on blinking slow green after it is restarted. On my Serial term on Mac (where my photon is connected via USB and powered), I can see the print messages coming from photon’s sketch (the one from the tutorial), but no print is displayed from the Bluz. (Please note that my bluz gateway was switched off after flashing my code. Even if it was on, I was seeing the same behaviour).

Every time this happens, I can’t flash back my old code (that doesn’t have Serial1 code) since it doesn’t connect to my bluz gateway. I have to reflash the bluz firmware using STLink.

Any idea what could be going wrong here? Also, if I keep my gateway up while debugging via another photon, would it create any issue, i.e. does gateway also use TX/RX of the bluz DK?

Any help would be very much appreciated.


Serial1 debug not working

@sdash, the user code on the bluz won’t run until it connects to the Cloud. So first things first.

Did you do this:

Make sure you gateway is running the latest firmware (1.0.5) and the Photon on the gateway is running the latest gateway app. You need to get your bluz connected to the cloud before you can test your app.

Once you have the above working, you can proceed with testing your app. Remember that the Photon and Bluz RX/TX pins need to be crossed (RX->TX, TX->RX). It may be a good idea to post your code as well. :wink:


Thanks @peekay123!

That’s interesting…
I have not done a “git pull” yet to upgrade my beta boards, and everything was working fine (bluz connecting to cloud via gateway etc) until I tried out the Serial debugging stuff.
The photon code is exactly same as given in the tutorials, and the serial print shows up in my PC’s Serial terminal. My app code has only added Serial1.begin(38400); and Serial1.print(“This is from Serial1 in bluz”); inside setup().

All my bluz firmware are fairly latest and compatible to each other (things mostly work including OTA flash from WebIDE.)
Yes, I need to anyway update to the latest release version, but before that I wanted to make things work with the current version … unless it stops me to do so due to some bugs or something.

Yes, I have connected the RX/TX correctly.

I understand that user code won’t work unless it’s paired up as a peripheral with the gateway. To me, that’s more like a current architecture limitation. I am working with @eric on that since my app use cases would need that.


Can you try powering bluz from the Photon? Just want to make sure it isn’t a setup issue. So if you follow the exact steps in the tutorial for hooking the two together, does it still not work?


I tried that already. But just tried now again to make sure. It still flashes green slowly. I have kept my gateway ON. Gateway and photon both are connected to cloud (breathes cyan and I can see them in device list - both CLI and my mobile app). Not sure what I’m doing wrong. Will try again, otherwise I will go ahead with git/firmware updates.

Here’s my bluz code (setup and loop), in case it helps:

int PWMA = D0; //Speed control
int AIN1 = D6; //Direction
int AIN2 = D5; //Direction
int STBY = A2; //standby

int SW1 = D3;

int INPUT_VOLTAGE_PIN = A0; // to read input voltage
unsigned long TIME_TO_LOCK_SWITCH = 1500;
float R1 = 20000.0;
float R2 = 10000.0;

void setup()
Particle.function(“servo”, operate_door_lock);
Particle.variable(“status”, &pos, INT);

// Motor Controller Setup
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);

// Switch Setup
pinMode(SW1, INPUT_PULLUP); // Enable internal pullup
digitalWrite(STBY, LOW); //enable standby

Serial1.println("Hello, I am a bluz on serial 1");


void loop()


Does bluz show up in the app?


It doesn’t show up in app or “particle list”.


@sdash, where in your code is operate_door_lock()?


I have not included that here since it’s only get called from app.
If you want, I can e-mail that to you separately since that’s part of our product code.


@sdash, I just needed to know you had it declared. I can flash this code via the web IDE on my working bluz and see how it behaves.


@peekay123, yes of course I declared :slight_smile: This function has been running all fine.


int operate_door_lock(String command)



Really appreciate your help on this. Let me know what you find.

I am going thru’ my code again and see what I changed exactly since it worked last.
It would have been easier to debug if this went into SOS mode or safe mode (breathing magenta). I have a feeling that i must have changed something which bluz didn’t like.


Just to be clear, do you mean it doesn’t show up in the bluz app? Or the particle app? If it is blinking green slowly, bluz is advertising and should be visible in the bluz app as a selectable option.

Did you flash code over the air from the Web IDE to this board? If yes, then you do need to run the python script, the cloud is using the latest code. I would recommend you run that regardless and use the latest code.


Yes. Ok, that’s the issue… Thanks @eric!

I am using particle-based app. Haven’t tried bluz app yet. Will work on that later.
I will next try out the latest code.

You mentioned in guide: “If you hook up to the serial line, then the script will flash production firmware once it is done. If not, then you must wait for the bootloader to finish and then flash production code yourself.”

-How do we flash production code?
-hooking up serial line means running CoolTerm/Serial etc?


Well, I used the bluz android app for flashing, but need to change my android app code to connect to bluz device.


Quick question: Do I need to do a clean build locally after a git pull?


Getting this error when running the programmer script:

Sanjoys-MacBook-Air:programmer_1-22-16 sanjoy$ python programmer.py -p jlink
Traceback (most recent call last):
File “programmer.py”, line 6, in
import serial
ImportError: No module named serial

I could flash using the old command after I did a build:

adalink nrf51822 --programmer stlink --wipe --program-hex …/bluzDK-firmware/build/target/system-part1/platform-103-m/system-part1.hex --program-hex …/bluzDK-firmware/build/target/user-part/platform-103-m/user-part.hex --program-hex …/bluzDK-firmware/platform/MCU/NRF51/NRF51_StdPeriph_Driver/inc/softdevice/s110/hex/s110_softdevice.hex --program-hex bluz/bootloader-0.1.2/bluz_bootloader.hex

from bluz-beta parent folder. Will this still do?
How do I flash the programmer?


Sorry, more issues :frowning:

I commented out ‘import serial’ and other call to Serial inside programmer.py. But I now the following error:

Sanjoys-MacBook-Air:programmer_1-22-16 sanjoy$ python programmer.py -p jlink
Namespace(port=’’, programmer=‘jlink’)
Welcome to bluz programmer!
Running with programmer jlink
Traceback (most recent call last):
File “programmer.py”, line 32, in
out = subprocess.check_output(args)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 710, in init
errread, errwrite)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”, line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

What version of python is needed? I have OS X 10.10.5.
I could figure out how to flash the production firmware after I am done with the other parts.


Looks like you are running it with jlink, but I believe you are using STLink, correct? Try changing jlink to stlink and see if that helps