Using to work with serial inputs [SOLVED]

I am attempting to start and stop an internal timer that calls an ADC sample in the Particle Photon using serial commands to control this functionality. I am using the RX/TX pins connected to a standard use bluetooth unit (JY-MCU H6), and the function does not seem to comprehend any of the inputs I send while using my serial terminal (Termite). My code is below:

int analogPin = A0;             // EMG connected to analog pin A0
int val = 0;                    // variable to store the read value
int count = 0;

void Hertz()
    val = analogRead(A0);  // read the input pin

Timer timer(2, Hertz);  // 500 Hz

void setup()
   pinMode(D7, OUTPUT);

void serial1Event()
    if (Serial1.available())
        char inByte =;
        if (inByte == '1'){
            digitalWrite(D7, HIGH);
            Serial1.println(;        //unix time stamp
        else if(inByte =='2'){
            digitalWrite(D7, LOW);
            Serial1.println(;        //unix time stamp
            count = 0;
void loop(){

It should be noted, that when I replace every “” with “” (ie, change the serial port FROM the RX/TX pins TO the usb port), the code operates flawlessly. I have done a fair amount of research on serial port operations in the Photon (both on this site, and elsewhere) and have seem to hit a wall. Any advice on how to successfully navigate this operation would be greatly appreciated.


Hi @aStringer4

I just have to ask because it has happened before: You have TX of the Photon connected to RX of the bluetooth module and vice-versa, right? That bluetooth module is capable of 3.3V operation, so you won’t need any resistors as in the Arduino circuits. You just need 3.3V and GND and then TX and RX connected to their opposite.

1 Like

Correct, RX/TX are inversely connect between the two chips. I should also mention that Serial1.print() functions correctly show up in the terminal, but the functions are not functioning properly.

1 Like

Could you add two else cases to catch and Serial.print() all possible outcomes of your tests?
Maybe your data gets corrupted and hence your branches don’t get executed, but knowing if and how would be required to understand the cause.

1 Like


I discovered there was an issue with the Bluetooth unit I was using. I followed this guide

in order to change the baud rate to 38400, and it was having additional side effects on the module. After restoring the bluetooth unit to its original functionality, is now functioning properly (but I am limited to 9600 baud for the time being). However, I have now discovered some heavy delay/overlap timing issues with my serialEvent() calling my timer operations, so I am now looking into this new problem. Any direction steering to useful information would be greatly appreciated. For now, I am making my rounds through the Software Timer section of the Particle References:

The more info you provide the more likely you get some useful info back.


After looking more closely at the Bluetooth unit I was using, I discovered the JY-MCU HC-06’s firmware has some issues interacting with the Particle Photon. Although an exact solution could not be determined, when using the HC-05 bluetooth unit (still following the arduino guide to change its baud rate to 38400, my original posted code worked fine. There was an issue with the timer priority causing the timer.stop() function call to not be executing, but I was able to fix this using pinned interrupts.

Sorry I’m not able to provide more specifics than this, but long story short, replacing the HC-06 with the HC-05 solved my problem.