Skip to content

Commit 7661ac1

Browse files
committed
Release v0.1
1 parent 56c3b4a commit 7661ac1

File tree

3 files changed

+175
-1
lines changed

3 files changed

+175
-1
lines changed

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,62 @@
1-
# arduino-crypto-tracker
1+
2+
# arduino-crypto-tracker
3+
It works only with the price of bitcoin (coindesk API), in the future it is planned to transfer to the coinmarketcap API.
4+
5+
## Components
6+
* Arduino Uno
7+
* ESP8266 (ESP01)
8+
* 1602A LCD
9+
* Wires
10+
11+
## Libs
12+
* ESP8266WiFi
13+
* ArduinoJson
14+
* SoftwareSerial
15+
* LiquidCrystal_I2C
16+
17+
## ESP8266 Firmware
18+
Connection diagram for ESP8266 firmware:
19+
|ESP8266|ARDUINO UNO |
20+
|--|--|
21+
|GND |GND |
22+
|VIN|3.3v |
23+
|ENABLE|3.3v |
24+
|TX|TX |
25+
|RX|RX |
26+
|RESET|GND |
27+
28+
> It is also necessary to close reset and gnd on the arduino.
29+
30+
Next, you need to hold down the reset button on the arduino and connect the arduino to the PC, after you hear that the USB-device is connected, you can release the button.
31+
32+
To update the ESP8266 firmware, you need to perform a number of manipulations with the Arduino IDE development environment.
33+
1. Open the **/api/api.ino** file, configure the wi-fi network
34+
2. Open **File** -> **Preferences** -> paste the link into the **Additional Board Manager URLs** http://arduino.esp8266.com/stable/package_esp8266com_index.json
35+
3. Open **Tools** -> **Boards** -> **ESP8266 Boards** -> **Generic ESP8266 Module**
36+
4. Install **ArduinoJson** library (**Tools** -> **Manage Libraries** -> Find and install)
37+
5. Compile and upload it to ESP8266.
38+
6. Profit!
39+
40+
## Final connection diagram
41+
Connection diagram for ESP8266 firmware:
42+
|ESP8266|ARDUINO UNO |
43+
|--|--|
44+
|GND |GND |
45+
|VIN|3.3v |
46+
|ENABLE|3.3v |
47+
|TX|Serial 3 |
48+
|RX|Serial 2 |
49+
50+
|LCD 1602A|ARDUINO UNO |
51+
|--|--|
52+
|GND |GND |
53+
|VCC|5v |
54+
|SDA|A4 |
55+
|SCL|A5 |
56+
Update Arduino Uno firmware:
57+
58+
1. Open the **/main/main.ino** file
59+
2. Open **Tools** -> **Boards** -> **Arduino AVR Board** -> **Arduino Uno**
60+
3. Install **LiquidCrystal_I2C** library (**Tools** -> **Manage Libraries** -> Find and install)
61+
4. Compile and upload it to ESP8266.
62+
5. Profit!

api/api.ino

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <ArduinoJson.h>
2+
#include <ESP8266WiFi.h>
3+
4+
const char* ssid = "TP-Link_408";
5+
const char* password = "84570550";
6+
7+
#define CD_API "/v1/bpi/currentprice.json"
8+
#define CD_URL "api.coindesk.com"
9+
10+
static char respBuffer[4096];
11+
WiFiClient client;
12+
13+
void setup() {
14+
Serial.begin(115200);
15+
delay(10);
16+
Serial.print("Connecting to ");
17+
Serial.println(ssid);
18+
WiFi.begin(ssid, password);
19+
while (WiFi.status() != WL_CONNECTED) {
20+
delay(500);
21+
Serial.print(".");
22+
}
23+
Serial.println("WiFi connected");
24+
Serial.print("IP address: ");
25+
Serial.println(WiFi.localIP());
26+
}
27+
28+
void loop() {
29+
getData();
30+
delay(7650);
31+
}
32+
33+
void getData() {
34+
const char request[] =
35+
"GET " CD_API " HTTP/1.1\r\n"
36+
"User-Agent: ESP8266/0.1\r\n"
37+
"Accept: */*\r\n"
38+
"Host: " CD_URL "\r\n"
39+
"Connection: close\r\n"
40+
"\r\n";
41+
delay(100);
42+
43+
if (!client.connect(CD_URL, 80)) {
44+
Serial.println("Connection failed");
45+
return;
46+
}
47+
48+
client.print(request);
49+
client.flush();
50+
delay(1000);
51+
uint16_t index = 0;
52+
while(client.connected() || client.available()) {
53+
if(client.available()) {
54+
respBuffer[index++] = client.read();
55+
delay(1);
56+
}
57+
}
58+
59+
char * json = strchr(respBuffer,'{');
60+
String json_str = String(json);
61+
uint16_t idx_d = json_str.lastIndexOf('d');
62+
json_str.remove(idx_d,3);
63+
DynamicJsonDocument doc(1024);
64+
DeserializationError error = deserializeJson(doc, json);
65+
66+
JsonObject bpi = doc["bpi"];
67+
JsonObject usd = bpi["USD"];
68+
String rate_float = usd["rate_float"];
69+
70+
Serial.print(rate_float);
71+
}

main/main.ino

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <SoftwareSerial.h>
2+
#include <LiquidCrystal_I2C.h>
3+
4+
SoftwareSerial esp8266(3, 2);
5+
LiquidCrystal_I2C lcd(0x27,16,2);
6+
7+
void setup() {
8+
Serial.begin(115200);
9+
Serial.println("Started");
10+
11+
esp8266.begin(115200);
12+
13+
lcd.init();
14+
lcd.backlight();
15+
lcd.print("Bitcoin");
16+
17+
}
18+
19+
String strData = "";
20+
boolean recievedFlag;
21+
22+
void loop() {
23+
24+
while (esp8266.available() > 0) {
25+
strData += (char)esp8266.read();
26+
recievedFlag = true;
27+
delay(2);
28+
}
29+
30+
if (recievedFlag) {
31+
lcd.setCursor(4, 1);
32+
lcd.print(strData);
33+
Serial.println(strData);
34+
strData = "";
35+
recievedFlag = false;
36+
}
37+
38+
39+
if (Serial.available()) {
40+
esp8266.write(Serial.read());
41+
}
42+
}

0 commit comments

Comments
 (0)