John R McAlpine V Mac
Published © MIT

BCH PL$ - A Retro Analog Bitcoin Cash Meter

BCH PL$ - A retro analog crypto meter powered by the Particle Cloud and a webhook API.

EasyFull instructions provided1 hour1,410
BCH PL$ - A Retro Analog Bitcoin Cash Meter

Things used in this project

Story

Read more

Schematics

BCH PLS Schematic

A digital readout is shown, but an analog meter is used for the project. There are only two connections. Please observe the proper polarity or the meter will run backwards.
Analog meter bch pls wp8unq37zr

Code

BCH_PLS

Arduino
Particle photon code
// Mac McAlpine UNCC MEGR3171 Indroduction to Instrumentation
//example code for testing the milliamp gauge with PWM and DAC pins.
//dac seems to output up to 10ma
//pwm seems to output up to 25ma with 100 ohm
//pwm with 3K in series with the 1ma FS meter seems to be an accurate match.
//Modified to publish a webhook event and receive cryptocurrency prices.
//webhook is included at the end of this code in the comments.

int ledpin = D7;
int pwmpin = D1;

Timer cointimer(10000, cointimerfunction);

void setup() {
    Serial.begin(230400);
    pinMode(DAC1, OUTPUT);
    pinMode(pwmpin, OUTPUT);
    pinMode(ledpin, OUTPUT);
    Particle.function("setgauge",setdac);
    //Particle.subscribe("hook-response/bitcoin2", bitcoinHandler, MY_DEVICES);  // Subscribe to the webhook response
    Particle.subscribe("hook-response/bchpls", bitcoinHandler, MY_DEVICES);  // Subscribe to the webhook response
    cointimer.start();
    cointimerfunction();  // Trigger initial bitcoin webhook
}


void cointimerfunction(){
     //Particle.publish("bitcoin2");  // Trigger bitcoin webhook
     bool success = Particle.publish("bchpls");  // Trigger bitcoin webhook
     if (success) 
     {
         digitalWrite(ledpin,HIGH);
     }
     
}


void loop() {
    int x=0;
    /*
    for (x=0; x<256; x++) {  //photon DAC current limit approx 10mA 
        analogWrite(DAC1, x);  //max is 4095
        analogWrite(pwmpin, x, 500); //last value is frequency in hz, 1-65535  max is 255
        Serial.println(x); //write is for byte value
        delay(10);
        
        // sets DAC pin to an output voltage of 1024/4095 * 3.3V = 0.825V.
        }
        delay(1000);
     */   
     //analogWrite(pwmpin,random(235),500); //generates randoms up to 235 using 256
     delay(250);
        
    //digitalWrite(ledpin,!digitalRead(ledpin));
}

int setdac(String command) {
    int commandint = command.toInt();
    if ((commandint >=0) && (commandint <=100)){
        commandint = map(commandint, 0, 100, 0, 255); //in low, high to out low, high
        analogWrite(pwmpin, commandint, 500); 
    }
}


void bitcoinHandler(const char *event, const char *data) {  // This is called when the Photon recives the webhook data.
    String latest = String(data);                  // Get the latest price of Bitcoin
    Serial.println(latest);                                     // Print it to serial
    coindac(latest);
    digitalWrite(ledpin, LOW);
    
}

int coindac(String command) {
    int commandint = command.toInt();
    if ((commandint >=1) && (commandint <=10000)){
        commandint = map(commandint, 0, 10000, 0, 258); //in low, high to out low, high
        analogWrite(pwmpin, commandint, 500); 
    }
}
    
/* PARTICLE WEBHOOK CODE - CUSTOM

{
    "event": "bchpls",
    "url": "https://min-api.cryptocompare.com/data/price?fsym=BCH&tsyms=USD",
    "requestType": "GET",
    "noDefaults": false,
    "rejectUnauthorized": true,
    "responseTemplate": "{{USD}}"
}
*/

Credits

John R McAlpine V Mac

John R McAlpine V Mac

11 projects • 31 followers
www.MACSBOOST.com Assistant Teaching Professor at UNC Charlotte MEGR3171 Instrumentation, Motorsports Research

Comments

Add projectSign up / Login