In this project I'm going to show you how to send messages to an Electron over the computer. I made this in my free time one day when I was bored and I thought some of you might like to use it too. If you're wondering why I didn't use a Photon for this, it's because they're all broken, but I can assure you this project is completely safe for your Electron or Photon! Even though the OLED shield was designed for the Photon, it works perfectly fine with an Electron. This is my first project so I'm sorry if anything is unclear.
AssemblyPut your Electron on the OLED shield just like you would put a Photon on. Make sure all of the pins line up (Pins C5- C0 & Pin B5 - B0 should be hanging off). I would recommend that you put the OLED shield onto the breadboard before you attach the Electron to it. That's really all there is to the setup, now there's only the code and the webpage left.
I'll assume you might know how to flash the code to the Electron, but since it's a little trickier (with the USB and all), here's the link: docs.particle.io. Copy the code below, then flash it to the Electron.
NOTE: Make sure the little yellow star under the devices section in the Build IDE is on your Electron or else the code won't go through. When you compile it, the library will flag, so delete the library and put it back in. Just search SPARKFUNMICROOLED
in the library section search bar and include the one ending in .h
and you should be all good!
#include "SparkFunMicroOLED/SparkFunMicroOLED.h"
String message = "";
MicroOLED oled;
void setup() {
oled.begin(); // Initialize the OLED
oled.clear(ALL); // Clear the display's internal memory
oled.display(); // Display what's in the buffer (splashscreen)
delay(1000); // Delay 1000 ms
oled.clear(PAGE); // Clear the buffer.
randomSeed(analogRead(A0) + analogRead(A1));
Particle.function("sender", messenger);
}
void loop() {
}
int messenger(String param){
if(param.length() <= 63){
message = param;
for (int i = 0; i < message.length(); i++) {
char letter = message.charAt(i);
oled.setCursor(10, 10);
oled.clear(PAGE);
oled.print(String(message));
oled.display();
delay(10000);
}
return 1;
}
else{
return -1;
}
}
If you have any problems with the code or web page, just leave a comment and I'll be happy to help!
Web PageThe web page is relatively easy, just open the file and insert your Access Token and Device ID where you see ACCESS TOKEN and DEVICE ID in the file. If you double click on it, the file should open, then you could open it in Atom, notes or wherever and put your Access Token and Device ID. It looks like this for me:
Just change Hello!
to whatever you want. Keep in mind that the message is displaying on the OLED screen, so something too long might not fit all the way. After a while the message you're sending stops going through, so just unplug the Electron and exit out of the window and try again.
Comments