Project tutorial
Spark (3.3v) to Arduino (5v) Serial Communication

Spark (3.3v) to Arduino (5v) Serial Communication © GPL3+

Photon / Spark Core and Arduino talk through serial.

  • 6,047 views
  • 0 comments
  • 13 respects

Components and supplies

About this project

(This is an adaptation/update from the original article written in the Particle Community forums.)

Here's how to get a Photon talking via serial to an Arduino using a logic level converter (I actually used one from eBay, but it works the same). The goal of this little test is to see if I could write from the Photon to the Arduino and listen for any serial data that the Arduino might generate. It's pretty simple and straightforward. Since my test Arduino is an Uno, I'm limited to SoftwareSerial, so I had to scale down the baud rate. I will eventually tap the Photon into an Arduino Mega which has multiple hardware serial ports *. The code is below the fancy graphics.

* Update!  I have tested communicating from a Photon <--> Arduino Mega this way, and it does work!  My test scenario was actually using a RAMPS 1.4 board (3D printer control board) and used hardware serial on both sides.  It worked (mostly) great!  The one caveat I discovered is that I think something has to be listening to serial communications on the other side of the Arduino Mega or a print can stall.  My theory is that it is waiting for something on the other end to read in or receive that serial communication or buffers will not be cleared in a timely fashion in the Marlin firmware.  I have no hard proof of this theory other than it worked well with something listening and would pause for several seconds at a time in mid-print when something wasn't listening.  When I disabled the additional serial output in the Marlin firmware, things started flowing normally again.


Code

photon.inoC/C++
The firmware for the Photon or Spark Core
void setup() {
	Particle.function("sendData", sendData);

	Serial.begin(9600);
	Serial1.begin(9600);
}


void loop() {
	if(Serial1.available())
		Serial.write(Serial1.read());
}


int sendData(String command) {
	Serial.print("INCOMING: ");
	Serial.println(command);

	Serial1.print("PARTICLE: ");
	Serial1.println(command);

	return 1;
}
arduino.inoC/C++
The code for the Arduino
#include <SoftwareSerial.h>

SoftwareSerial ser(2,3);

void setup() {
  Serial.begin(9600);
  Serial.println("SERIAL: BEGIN");

  ser.begin(9600);
  ser.println("SOFTWARE SERIAL: BEGIN");
}


void loop() {
  if(ser.available())
    Serial.write(ser.read());
}

Schematics

Photon-Serial-Arduino
Photon serial arduino

Comments

Similar projects you might like

Serial Communication between NodeMCU and Arduino

Project showcase by Pawan Kumar

  • 10,747 views
  • 2 comments
  • 14 respects

Enter the house like a Sith Lord

Project tutorial by Prasantha Jayakody

  • 18,118 views
  • 10 comments
  • 70 respects

Arduino - Serial Communication Visual Studio

Project tutorial by whitebank

  • 16,291 views
  • 5 comments
  • 16 respects

LoPy - Arduino Serial Communication

by Rob Braggaar

  • 3,469 views
  • 1 comment
  • 10 respects

Arduino I2C communication with Raspi 2 WIOT

Project tutorial by Christiano Faig

  • 35,434 views
  • 25 comments
  • 112 respects
Add projectSign up / Login