Skip to content

Instantly share code, notes, and snippets.

@nrobinson2000
Last active April 2, 2016 20:03
Show Gist options
  • Save nrobinson2000/2deeefc6f71c7ee94ece to your computer and use it in GitHub Desktop.
Save nrobinson2000/2deeefc6f71c7ee94ece to your computer and use it in GitHub Desktop.
Display the price of Bitcoin with a Photon.
{
"eventName": "bitcoin",
"url": "https://api.bitcoinaverage.com/ticker/global/USD/",
"requestType": "GET",
"mydevices": true
}
/*
Bitcoin Monitor:
This sketch shows the current Bitcoin price
on an LCD.
The circuit:
* LCD RS pin to digital pin D0
* LCD EN pin to digital pin D1
* LCD D4 pin to digital pin D2
* LCD D5 pin to digital pin D3
* LCD D6 pin to digital pin D4
* LCD D7 pin to digital pin D5
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* connect R/W (pin 5) to ground
*/
#include "LiquidCrystal/LiquidCrystal.h"
LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);
void setup()
{
lcd.begin(16,2); // set up the LCD's number of columns and rows:
lcd.print("Bitcoin Price:"); // Print a message to the LCD.
Particle.publish("bitcoin"); // Trigger bitcoin webhook
Particle.subscribe("hook-response/bitcoin/0", bitcoinHandler, MY_DEVICES); // Subscribe to the webhook response
Serial.begin(9600); // Begin serial
}
void loop()
{
if (millis()/1000 % 10 == 0) // Every ten seconds
{
Particle.publish("bitcoin"); // Trigger bitcoin webhook
}
}
void bitcoinHandler(const char *event, const char *data) // This is called when the Photon recives the webhook data.
{
Serial.println(data); // Print the data to serial for debugging
String ask = String(getAskPrice(data)); // Get the ask price of Bitcoin
Serial.println(ask); // Print it to serial
lcd.setCursor(0, 1); // Set the cursor to the second line
lcd.print(" "); // Clear the second line
lcd.setCursor(0,1); // Reset cursor
lcd.print(ask); // Print the price of bitcoin
lcd.print(" USD"); // Print "USD" after
}
String getAskPrice(String data) // This function gets the value in the "ask:" part of the JSON.
{
int kLocation = data.indexOf("k"); // Find where the "k" of ask appears
int commaLocation = data.indexOf(",", kLocation); // Find where the comma after the value appears
String value = data.substring(kLocation +4, commaLocation); // The value is from 4 characters after where "k" is and right before where the comma is.
return value; // Return the ask price of Bitcoin
}
@nrobinson2000
Copy link
Author

Bitcoin Price Monitor:

To make this project you need a standard 16x2 LCD display, a breadboard, a Particle Photon and a Potentiometer.

1.) Wire up the LCD to the Photon like so:

  • LCD RS pin to digital pin D0
  • LCD EN pin to digital pin D1
  • LCD D4 pin to digital pin D2
  • LCD D5 pin to digital pin D3
  • LCD D6 pin to digital pin D4
  • LCD D7 pin to digital pin D5
  • LCD A to 3v3
  • LCD K to ground
  • R/W (pin 5) to ground
  • Potentiometer ends to VIN and ground
  • Potentiometer wiper to LCD VO pin (pin 3)

2.) Flash the LCD-Bitcoin-Monitor.ino file to your Photon by copying and pasting it into Particle Build and clicking on the flash icon.

3.) Upload the bitcoin.json file to your Particle account:

  • $ particle webhook create bitcoin.json

4.) Click reset on your Photon and enjoy your bitcoin price monitor!

img_1791

Want to donate to my Projects? Click Here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment