Photon: using Serial1 to get data form external mcu

Hi
I am intend to send serial data to the Photon Rx pin from external mcu.
I browsed through different posts but I couldn’t find a answer for this case.
The code works partially well because I am receiving the the string that simulate a sensor reading but I got a series of repeated figures like "32.3432.24.32.24??32.24 etc. when what I sent was 32.24 every 2000 ms from the external mcu.
I’m using Blynk libraries and specifically the Label value display.
There are other issues I can realize like a sequence of led state like this:

one blink white/red.
Fast green.
Fast Cyan
Breathing Cyan
Many red blink that I can’t account for.
and loop again to one blink white/red.

During this loop the blink app keeps showing the message " device was disconnected" and then update the Label value display con the simulated sensor reading and so on.
This is my first project in addition to Blink a led :slight_smile:.
Here is the code:
Thank you for some help.

/*************************************************************
    App project setup:
    Value Display widget attached to V5
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial1


#include <blynk.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

char Ampstr[6];
BlynkTimer timer;



void setup()
{

  // Debug console
  Serial1.begin(56700);

  delay(5000); // Allow board to settle
  Blynk.begin(auth);

  // Setup a function to be called every second
  timer.setInterval(100L, sendAmp);
}


void sendAmp()
{
 
  
 int i=0;



      while (Serial1.available() >0  ) 
      {  
     
     
      Ampstr[i] = Serial1.read(); 
   
   if(  Ampstr[i]=='\0'   )
         { break;}
          i++;
     
      }
 
     i=0;

    // Send it to the server
  Blynk.virtualWrite(V7, Ampstr);
 
  
} 
 


void loop()
{

  Blynk.run();
  timer.run();

}

I guess your “many red blinks” are an SOS panic pattern followed by a number of slower blinks. That number is relevant for error diagnosis.

The reason seems to be due to running out of your 6 char buffer with incrementing i but not resetting in time.

One counter measure would be to change your while() like this

 while ( Serial1.available() && i < 6  ) 

And add Ampstr[5] = '\0'; after your i=0; line.

1 Like

ScruffR… men this what I call real time help !!! now works nice.

Can I try other real time help?
my first photon worked OK the first days with USB. I used the CLI to play a little and get to know how it work.
One day using the USB I got Blue screen on my laptop.
I am working with windows 7 64 bit and I know that win 7 is not good for Photon.
But I am trying to install the correct driver based on the info from Git Hub on this link:

But the point I have no chance to do nothing because as soon as I connect Photon to USB on my laptop I got Blue screen and I need to wait the computer reboot.
Is the photon damaged?
Thank you very much again.

Hmm, after having reports of bluescreens on Windows I did some experiments and the only time I got them to happen “reliably” was together with TeraTerm (irrespective of Windows version).
I’ve never had issues with CLI or PuTTY, so I’m not sure what’s causing your troubles.

But I’d try to remove all drivers connected with Particle/Spark (using DEVMGR_SHOW_NONPRESENT_DEVICES) and reinstall the drivers via the CLI installer

@ScruffR
Yes I would do that if I could.
The point is that wherever app the laptop is running , for example just on desktop and I plug in the USB connector on the laptop’s USB port I get Blue screen.
That’s way I am wondering if the Photon is damaged , because the Laptop’s USB port work OK with anything.
Thank you very much for your help.

Interesting. Did you only get the BSOD when you disconnected the Photon without disconnecting from TerraTerm?

Maybe I should try Putty and see if my BSOD issues go away.

@ScruffR
I would like Highlight that I getting BSOD independently the application is running on my laptop.
So if I am running for example CLI Once I install Putty I will try again.
If I am running Microsoft excel Once I install Putty I will try again…
Once I install Putty I will try again.
Thank you.

@ScruffR
Hi ScruffR I’m sorry I had an edition issue.
I would like Highlight that I getting BSOD independently the application is running on my laptop.
So if I am running for example CLI and plug my Photon I get BSOD.
If I am running Microsoft excel an plug my Photon I get BSOD.
Whichever app is running I get BSOD and I need to wait the computer boot up again.
I will install Putty and I will try again.
Thank you.