Porting from Arduino to Particle.io (Simplified-Hopefully)


That solves it, but we can speed up the build farm from being “aware” of the new .ino file by making a small change in the file and then compiling (insert a blank line anywhere!). The changed file gets properly saved and then it can compile immediately.

Thanks @ScruffR I was going a little crazy about this issue. Possibly this issue can be tweaked on Particle’s side. The “Use This Example” button may not be fully initializing all variables, or the file is being saved too early and just re-save the file or save the file at the end of the process.

The easiest solution is probably something like

printf "\n " >> filename.ino

In linux that would add a new line to the end of the file.


On the theme of teaching students how to port Arduino libraries. I have just completed my first library using my template at

You can find the new library by searching for pixycam5 in the library tab on the particle.io IDE.

Information about the MIT Pixy camera is at http://cmucam.org/projects/cmucam5

Basically it detectsw up to 7 colorsand can then detect multiple objects on the screen. Advanced use combines colors for color tagged objects.

My github ported library is at

The two .ino files are a01-pixy-d7.ino which tests if the camera has detected an object with a width over 10 pixels and then the D7 LED flashes.

The second file is called a02-pixy-serial.ino and it prints all the pixy serial informatioin over the usb connection to your computer.

Remember the trick to make a change to the file and save it as soon as you have used the “Use This Example” before you compile the file.


So the last thing I need to cover is the PINS used for different serial protocols. To the experts, the datasheets at https://docs.particle.io/datasheets/photon-datasheet/ should tell it all, but us lowly mortals need a bit more guidance. The images in questions are:

As far as I can tell, if the Arduino file you are porting uses the include SPI.h (which can be commented out for the Photon) then the PIN connections should be

SCK to A3

MISO to A4

MOSI to A5

If the Arduino file uses UART communication (which doesn’t seem to have a specific include file except include application.h or Arduino.h) which when porting to the Photon we would change the include to include Particle.h and the RX/TX communication is a bit confusing since RX on the device goes to TX on the Photon and vice-versa.

I2C I am not to sure about except it looks like the include file would be include Wire.h which can be commented out on the Photon.

Pin D1 connects to SCL
Pin D0 connects to SDA

Anyone like to add some words of wisdom to this? @peekay123 perhaps.


Yes, you are correct on the pin assignments. For SPI you also need a SS pin, by default this is A2, but you can use any output pin as a SS (slave select).

For I2C those are the pins. Remember the I2C needs pull-up resistors. If the device you are connecting doesn’t have them built in (some shields have them, actual device chips generally don’t), you’ll need to add some. Perhaps a 4.7K resistor to either 5V or 3.3V depending on whether the I2C device is 5V or 3.3V, on both the SDA and SCL lines.

For serial, TX always connects to RX and vice versa. That’s because TX means transmitted from the device, which means it must be received into the other device. From the other device’s viewpoint, that’s RX, received into the device. You do need to #include “Serial1/Serial1.h” in order to use the serial port on the RX and TX pins using the Serial1 object. [EDIT: Actually, you only need the include for Serial2 and higher. Oops.]


Nope, Serial1 is there by default - only Serial2, 4, 5 (where present - e.g. Electron - and there is no 3 for yet existing devices).


The wire.h is done implicitly in Particle.h (aka application.h) so no need to include. :wink:


Hence @rocksetta did say so :wink:


@ScruffR, argh! Not enough sleep = not paying attention = DOH! :flushed:


Thanks for the informative replies.

Can you explain a bit more about the SPI.h SS pin (A2). I have connected a PIXY camera to the Photon https://github.com/hpssjellis/particle-photon-pixy-camera (Particle IDE library pixycam5) without using the SS pin. Can you expand on what the SS pin is used for?


The SS (slave select pin, sometimes called CS or EN) allows multiple devices to connect to a single SPI bus. It’s an active-low signal that basically tells the device it’s the one that’s active or selected. In some cases, where there’s only one device on the bus, that line can just be tied low, saving a GPIO. And some devices don’t have a SS pin; they can be the only device on that SPI bus. It looks like the Pixy is one of those.


Great reply. That actually really makes sense.


I spent a fair bit of time trying to make porting from the Arduino to the Photon and working with Libraries easier last year.

My github site is at:

With the new library changes my github site is now out-of-date. It was a framework for students to easily make a library entry.

Any chance a Particle team member could make a pull request with the new library changes? I am sure it would not take @peekay123 very long to make the changes :confused: