I am using the Particle Build and by extending the base tinker application with including the Serial2 header and adding “Serial2.begin(115200);” to the setup the result is that the photon goes into an akward state after connecting to the network where the led will only momentarily flash when an input from the serial is received (flash is in green color) and cloud connection seems not to work - OTA flashing results in a hard fault.
Hi all,
I am having exactly the same issue. using the D0 and D1 pins as soon as i call the Serial2.begin(9600); the photon goes into a very weird state. The RGB led just turns off but my code still seems to be running. I am also running firmware 0.4.5
Serial2 on the photon shares pins with the RGB LED, not D0/D1 on the Core. Sorry for the misinformation - I've filed an issue to have the docs updated.
Thanks for the clarification.
So if i understand correctly, to use the Serial2 i can solder wires to the RGB led pads that are available on the reverse side of the photon?
The Photon firmware at present doesn’t officially support Serial2 - we’re providing this information in the hope that it useful, but operation isn’t guaranteed. If it does work for you please let us know!
I meant the D0 and D1 (which were mistakenly referred to in the docs), I guess I’ll go over to Serial1 seeing as Serial2 requires special methods for utilizing it.
Serial2 is working on the Photon and P1, you just need to make sure the Blue and Green segments of the RGB LED are disconnected. I have tested it without disconnecting the LED segments and it works, but one time I was getting feedback from the LEDs. LEDs can shine when you are TX’ing and the LED that’s attached to the RX line can actually work like an octocoupler and echo garbage on the RX line, hence it’s better to disconnect them. On the Photon this would mean desoldering the series 1k ohm resistors. Not ideal, but if you really need an extra HW serial interface, it’s there to use. You would then need to hook up your own RGB LED to alternate pins that are PWM capable using the .onChange() handler, see an example here: https://docs.particle.io/reference/firmware/photon/#onchange-handler- (note: example uses a common anode RGB LED)
NOTE the following example blinks the RED segment of the RGB so don’t think it’s an error code
/*
******************************************************************************
* Copyright (c) 2015 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/
#include "application.h"
#include "Serial2/Serial2.h"
SYSTEM_MODE(AUTOMATIC);
uint32_t now = millis();
uint32_t lastFlash = now;
/* executes once at startup */
void setup()
{
// Not necessary, but you can do this as well
// RGB.control(true);
// RGB.color(0,0,0);
pinMode(RGBR, OUTPUT);
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);
Serial.println("Hi, I'm Serial USB!\r\n"); //Press 1 to talk to Serial1 or 2 to talk to Serial2.");
}
/* executes continuously after setup() runs */
void loop()
{
now = millis();
if (now - lastFlash > 300UL) {
lastFlash = now;
// This blinks the RED segment of the RGB led
// NOTE: You cannot use the BLUE or GREEN segment
// of the RGB anymore while using Serial2.
digitalWrite(RGBR, !digitalRead(RGBR));
}
if(Serial.available()) {
char c = Serial.read();
if (c == '1') Serial1.println("Hi, I'm Serial 1!\r\nType in here to talk to Serial USB.");
else if (c == '2') Serial2.println("Hi, I'm Serial 2!\r\nType in here to talk to Serial USB.");
}
// If you type on your Serial1 terminal it will appear on Serial USB
if (Serial1.available()) {
char c = Serial1.read();
Serial.write(c);
}
// If you type on your Serial2 terminal it will appear on Serial USB
if (Serial2.available()) {
char c = Serial2.read();
Serial.write(c);
}
}