temperature monitoring of 10k ntc
This commit is contained in:
parent
eb9ad3c75a
commit
df42d18944
@ -16,6 +16,7 @@
|
|||||||
#include "timeconst.h"
|
#include "timeconst.h"
|
||||||
#include "drivers/nerd-nos/bm1397.h"
|
#include "drivers/nerd-nos/bm1397.h"
|
||||||
#include "drivers/nerd-nos/serial.h"
|
#include "drivers/nerd-nos/serial.h"
|
||||||
|
#include "drivers/nerd-nos/adc.h"
|
||||||
|
|
||||||
#ifdef NERD_NOS
|
#ifdef NERD_NOS
|
||||||
#include "mining_nerdnos.h"
|
#include "mining_nerdnos.h"
|
||||||
@ -147,6 +148,7 @@ void setup()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NERD_NOS
|
#ifdef NERD_NOS
|
||||||
|
nerdnos_adc_init();
|
||||||
SERIAL_init();
|
SERIAL_init();
|
||||||
int chips = BM1397_init(200, 1);
|
int chips = BM1397_init(200, 1);
|
||||||
Serial.printf("found bm1397: %d\n", chips);
|
Serial.printf("found bm1397: %d\n", chips);
|
||||||
|
@ -25,7 +25,7 @@ void tDisplay_Init(void)
|
|||||||
pinMode(PIN_ENABLE5V, OUTPUT);
|
pinMode(PIN_ENABLE5V, OUTPUT);
|
||||||
digitalWrite(PIN_ENABLE5V, HIGH);
|
digitalWrite(PIN_ENABLE5V, HIGH);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tft.init();
|
tft.init();
|
||||||
#ifdef LILYGO_S3_T_EMBED
|
#ifdef LILYGO_S3_T_EMBED
|
||||||
tft.setRotation(ROTATION_270);
|
tft.setRotation(ROTATION_270);
|
||||||
@ -65,9 +65,13 @@ void tDisplay_MinerScreen(unsigned long mElapsed)
|
|||||||
|
|
||||||
// Print background screen
|
// Print background screen
|
||||||
background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
|
background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
|
||||||
|
#ifdef NERD_NOS
|
||||||
|
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s GH/s, %s °C\n",
|
||||||
|
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str(), data.currentTemperature.c_str());
|
||||||
|
#else
|
||||||
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
|
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
|
||||||
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
|
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
// Hashrate
|
// Hashrate
|
||||||
render.setFontSize(35);
|
render.setFontSize(35);
|
||||||
@ -211,7 +215,7 @@ void tDisplay_BTCprice(unsigned long mElapsed)
|
|||||||
{
|
{
|
||||||
clock_data data = getClockData(mElapsed);
|
clock_data data = getClockData(mElapsed);
|
||||||
data.currentDate ="01/12/2023";
|
data.currentDate ="01/12/2023";
|
||||||
|
|
||||||
//if(data.currentDate.indexOf("12/2023")>) { tDisplay_ChristmasContent(data); return; }
|
//if(data.currentDate.indexOf("12/2023")>) { tDisplay_ChristmasContent(data); return; }
|
||||||
|
|
||||||
// Print background screen
|
// Print background screen
|
||||||
@ -231,14 +235,14 @@ void tDisplay_BTCprice(unsigned long mElapsed)
|
|||||||
render.rdrawString(data.blockHeight.c_str(), 254, 138, TFT_WHITE);
|
render.rdrawString(data.blockHeight.c_str(), 254, 138, TFT_WHITE);
|
||||||
|
|
||||||
// Print Hour
|
// Print Hour
|
||||||
|
|
||||||
background.setFreeFont(FSSB9);
|
background.setFreeFont(FSSB9);
|
||||||
background.setTextSize(1);
|
background.setTextSize(1);
|
||||||
background.setTextDatum(TL_DATUM);
|
background.setTextDatum(TL_DATUM);
|
||||||
background.setTextColor(TFT_BLACK);
|
background.setTextColor(TFT_BLACK);
|
||||||
background.drawString(data.currentTime.c_str(), 222, 3, GFXFF);
|
background.drawString(data.currentTime.c_str(), 222, 3, GFXFF);
|
||||||
|
|
||||||
// Print BTC Price
|
// Print BTC Price
|
||||||
background.setFreeFont(FF24);
|
background.setFreeFont(FF24);
|
||||||
background.setTextDatum(TR_DATUM);
|
background.setTextDatum(TR_DATUM);
|
||||||
background.setTextSize(1);
|
background.setTextSize(1);
|
||||||
|
48
src/drivers/nerd-nos/adc.cpp
Normal file
48
src/drivers/nerd-nos/adc.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "driver/adc.h"
|
||||||
|
#include "esp_adc_cal.h"
|
||||||
|
|
||||||
|
#define ADC_CHANNEL ADC1_CHANNEL_1 // GPIO2 corresponds to ADC1 channel 1 on ESP32-S3
|
||||||
|
#define BETA 3380 // Beta value of the thermistor
|
||||||
|
#define R0 10000 // Resistance at 25°C (10kΩ)
|
||||||
|
#define ADC_MAX 4095 // Max ADC value for 12-bit resolution
|
||||||
|
#define DEFAULT_VREF 1100 // Default VREF in millivolts for ESP32 ADC
|
||||||
|
|
||||||
|
// ADC Calibration characteristics
|
||||||
|
static esp_adc_cal_characteristics_t adc1_chars;
|
||||||
|
|
||||||
|
void nerdnos_adc_init() {
|
||||||
|
// Configure the ADC
|
||||||
|
adc1_config_width(ADC_WIDTH_BIT_12); // Set ADC width (12-bit)
|
||||||
|
adc1_config_channel_atten(ADC_CHANNEL, ADC_ATTEN_DB_11); // Set attenuation to read the full range of 0 to 3.3V
|
||||||
|
|
||||||
|
// Characterize ADC at given attenuation
|
||||||
|
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 0, &adc1_chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
float nerdnos_get_temperature() {
|
||||||
|
// Convert the raw ADC value to a voltage using esp_adc_cal
|
||||||
|
uint32_t voltage_mv = esp_adc_cal_raw_to_voltage(adc1_get_raw(ADC_CHANNEL), &adc1_chars); // Voltage in millivolts
|
||||||
|
|
||||||
|
// Convert millivolts to volts
|
||||||
|
float voltage = voltage_mv / 1000.0;
|
||||||
|
|
||||||
|
// Ensure the voltage is within a valid range
|
||||||
|
if (voltage <= 0) {
|
||||||
|
printf("Error: Invalid voltage reading.\n");
|
||||||
|
return -273.15; // Return a clearly invalid temperature to indicate an error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the thermistor resistance using the voltage divider formula
|
||||||
|
// R_T = R0 * (Vout / (VREF - Vout))
|
||||||
|
float thermistor_resistance = R0 * (voltage / (3.3 - voltage));
|
||||||
|
|
||||||
|
// Use the Beta parameter equation to calculate the temperature in Kelvin
|
||||||
|
float temperature_kelvin = (float)(BETA / (log(thermistor_resistance / R0) + (BETA / 298.15)));
|
||||||
|
|
||||||
|
// Convert the temperature to Celsius
|
||||||
|
float temperature_celsius = temperature_kelvin - 273.15;
|
||||||
|
|
||||||
|
return temperature_celsius;
|
||||||
|
}
|
4
src/drivers/nerd-nos/adc.h
Normal file
4
src/drivers/nerd-nos/adc.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void nerdnos_adc_init();
|
||||||
|
float nerdnos_get_temperature();
|
@ -63,8 +63,8 @@ static void _send_BM1397(uint8_t header, uint8_t *data, uint8_t data_len, bool d
|
|||||||
packet_type_t packet_type = (header & TYPE_JOB) ? JOB_PACKET : CMD_PACKET;
|
packet_type_t packet_type = (header & TYPE_JOB) ? JOB_PACKET : CMD_PACKET;
|
||||||
uint8_t total_length = (packet_type == JOB_PACKET) ? (data_len + 6) : (data_len + 5);
|
uint8_t total_length = (packet_type == JOB_PACKET) ? (data_len + 6) : (data_len + 5);
|
||||||
|
|
||||||
// allocate memory for buffer
|
// memory for buffer
|
||||||
unsigned char *buf = (unsigned char *)malloc(total_length);
|
uint8_t buf[total_length];
|
||||||
|
|
||||||
// add the preamble
|
// add the preamble
|
||||||
buf[0] = 0x55;
|
buf[0] = 0x55;
|
||||||
@ -93,8 +93,6 @@ static void _send_BM1397(uint8_t header, uint8_t *data, uint8_t data_len, bool d
|
|||||||
|
|
||||||
// send serial data
|
// send serial data
|
||||||
SERIAL_send(buf, total_length, debug);
|
SERIAL_send(buf, total_length, debug);
|
||||||
|
|
||||||
free(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _send_read_address(void)
|
static void _send_read_address(void)
|
||||||
|
@ -129,7 +129,6 @@ void nerdnos_create_job(mining_subscribe *mWorker, mining_job *job, bm_job_t *ne
|
|||||||
calculate_merkle_root_hash(coinbase_tx.c_str(), job, merkle_root);
|
calculate_merkle_root_hash(coinbase_tx.c_str(), job, merkle_root);
|
||||||
|
|
||||||
//Serial.printf("asic merkle root: %s\n", merkle_root);
|
//Serial.printf("asic merkle root: %s\n", merkle_root);
|
||||||
// we need malloc because we will save it in the job array
|
|
||||||
construct_bm_job(job, merkle_root, 0x1fffe000, next_job);
|
construct_bm_job(job, merkle_root, 0x1fffe000, next_job);
|
||||||
|
|
||||||
next_job->jobid = strdup(job->job_id.c_str());
|
next_job->jobid = strdup(job->job_id.c_str());
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#ifdef NERD_NOS
|
#ifdef NERD_NOS
|
||||||
#include "mining_nerdnos.h"
|
#include "mining_nerdnos.h"
|
||||||
|
#include "drivers/nerd-nos/adc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern uint32_t templates;
|
extern uint32_t templates;
|
||||||
@ -243,11 +244,19 @@ String getCurrentHashRate(unsigned long mElapsed) {
|
|||||||
// we have too little space for 2 digits after the decimal point
|
// we have too little space for 2 digits after the decimal point
|
||||||
return String(nerdnos_get_avg_hashrate(), 1);
|
return String(nerdnos_get_avg_hashrate(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getCurrentTemperature() {
|
||||||
|
return String(nerdnos_get_temperature(), 2);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
String getCurrentHashRate(unsigned long mElapsed)
|
String getCurrentHashRate(unsigned long mElapsed)
|
||||||
{
|
{
|
||||||
return String((1.0 * (elapsedKHs * 1000)) / mElapsed, 2);
|
return String((1.0 * (elapsedKHs * 1000)) / mElapsed, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getCurrentTemperature() {
|
||||||
|
return String(0.0, 2);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mining_data getMiningData(unsigned long mElapsed)
|
mining_data getMiningData(unsigned long mElapsed)
|
||||||
@ -269,6 +278,7 @@ mining_data getMiningData(unsigned long mElapsed)
|
|||||||
data.totalMHashes = Mhashes;
|
data.totalMHashes = Mhashes;
|
||||||
data.totalKHashes = totalKHashes;
|
data.totalKHashes = totalKHashes;
|
||||||
data.currentHashRate = getCurrentHashRate(mElapsed);
|
data.currentHashRate = getCurrentHashRate(mElapsed);
|
||||||
|
data.currentTemperature = getCurrentTemperature();
|
||||||
data.templates = templates;
|
data.templates = templates;
|
||||||
data.bestDiff = best_diff_string;
|
data.bestDiff = best_diff_string;
|
||||||
data.timeMining = timeMining;
|
data.timeMining = timeMining;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
//Time update period
|
//Time update period
|
||||||
#define UPDATE_PERIOD_h 5
|
#define UPDATE_PERIOD_h 5
|
||||||
|
|
||||||
//API BTC price (Update to USDT cus it's more liquidity and flow price updade)
|
//API BTC price (Update to USDT cus it's more liquidity and flow price updade)
|
||||||
#define getBTCAPI "https://api.blockchain.com/v3/exchange/tickers/BTC-USDT"
|
#define getBTCAPI "https://api.blockchain.com/v3/exchange/tickers/BTC-USDT"
|
||||||
#define UPDATE_BTC_min 1
|
#define UPDATE_BTC_min 1
|
||||||
|
|
||||||
@ -73,6 +73,7 @@ typedef struct {
|
|||||||
String valids;
|
String valids;
|
||||||
String temp;
|
String temp;
|
||||||
String currentTime;
|
String currentTime;
|
||||||
|
String currentTemperature;
|
||||||
}mining_data;
|
}mining_data;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -81,7 +82,7 @@ typedef struct {
|
|||||||
String currentHashRate;
|
String currentHashRate;
|
||||||
String btcPrice;
|
String btcPrice;
|
||||||
String blockHeight;
|
String blockHeight;
|
||||||
String currentTime;
|
String currentTime;
|
||||||
String currentDate;
|
String currentDate;
|
||||||
}clock_data;
|
}clock_data;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user