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.

  • 5,403 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

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 455,829 views
  • 44 comments
  • 242 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,638 views
  • 95 comments
  • 672 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 231,068 views
  • 38 comments
  • 241 respects

OpenCat

Project in progress by Team Petoi

  • 196,709 views
  • 154 comments
  • 1,366 respects
Add projectSign up / Login