We are onto post number 9 or 10 and the code from post#1 is still not in code tags.
Consider this a test. Can you follow instructions. If you can, we'll most likely have success helping you. If not then not.
We are onto post number 9 or 10 and the code from post#1 is still not in code tags.
Consider this a test. Can you follow instructions. If you can, we'll most likely have success helping you. If not then not.
#include
#include "ThingSpeak.h"
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run make menuconfig
to and enable it
#endif
float adc_voltage = 0.0;
float adc_voltage1 = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
float ref_voltage = 17.0;
float adc_value = 0;
WiFiClient client;
unsigned long myChannelNumber = 1714718;
const char * myWriteAPIKey = "9U3QMIMX97S6QCUE";
// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;
unsigned long lastTime1 = 0;
unsigned long timerDelay1 = 30000;
#include "BluetoothSerial.h"
int fl=0;
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run make menuconfig
to and enable it
#endif
String ssid="BTBHub6-36JX"; // your network SSID (name)
String password="FUqJi7uU7AJE";
char* ssid1="Raheem";
char* password1="kolachi";
BluetoothSerial SerialBT;
void setup() {
Serial.begin(9600); //Initialize serial
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
SerialBT.begin("Boat"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(33,OUTPUT);
pinMode(32,OUTPUT);
delay(5000);
//blue();
}
void blue(){
Serial.println("Enter wifi Name");
ab:
digitalWrite(33,HIGH);
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
ssid =SerialBT.readString();
Serial.print(ssid);
}
else {
goto ab;
}
Serial.println("Enter password");
ac:
digitalWrite(33,LOW);
digitalWrite(32,HIGH);
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
password =SerialBT.readString();
Serial.print(password);
fl=1;
}
else {
goto ac;
}
}
void battery1(){
update1:
adc_value = analogRead(35);
Serial.print("b1");
Serial.println(adc_value); // lets assume
adc_voltage = (adc_value * ref_voltage) / 4096.0;
Serial.println(adc_voltage);
if ((millis() - lastTime) > timerDelay) {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid.c_str(), password.c_str());
delay(5000);
if(WiFi.status() != WL_CONNECTED){
Serial.println("Enter correct wifi and pass");
//blue();
}
}
Serial.println("\nConnected.");
}
delay(1000);
int x = ThingSpeak.writeField(myChannelNumber, 1,adc_voltage, myWriteAPIKey);
if(x == 200){
digitalWrite(33,LOW);
digitalWrite(32,LOW);
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
goto update1;
}
lastTime = millis();
}
}
void battery2(){
update2:
adc_value = analogRead(34);
Serial.print("b2");
Serial.println(adc_value);
adc_voltage1 = (adc_value * ref_voltage) / 4096.0;
Serial.println(adc_voltage1);
if ((millis() - lastTime1) > timerDelay1) {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid.c_str(), password.c_str());
delay(5000);
if(WiFi.status() != WL_CONNECTED){
Serial.println("Enter correct wifi and pass");
// blue();
}
}
Serial.println("\nConnected.");
}
delay(1000);
int z = ThingSpeak.writeField(myChannelNumber, 2,adc_voltage1, myWriteAPIKey);
if(z == 200){
digitalWrite(33,LOW);
digitalWrite(32,LOW);
Serial.println("Channel 2 update successful.");
}
else{
Serial.println("Problem updating channel 2. HTTP error code " + String(z));
goto update2;
}
lastTime1 = millis();
}
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
char fl =SerialBT.read();
delay(5000);
if (fl=='2'){
blue();
}
}
battery1();
delay(1000);
battery2();
delay(1000);
}
is this better
No.
No
Did you do what I suggested in post #4 and use "Copy for Forum" in the IDE ?
#include <WiFi.h>
#include "ThingSpeak.h"
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
float adc_voltage = 0.0;
float adc_voltage1 = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
float ref_voltage = 17.0;
float adc_value = 0;
WiFiClient client;
unsigned long myChannelNumber = 1714718;
const char * myWriteAPIKey = "9U3QMIMX97S6QCUE";
// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;
unsigned long lastTime1 = 0;
unsigned long timerDelay1 = 30000;
#include "BluetoothSerial.h"
int fl=0;
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
String ssid="BTBHub6-36JX"; // your network SSID (name)
String password="FUqJi7uU7AJE";
char* ssid1="Raheem";
char* password1="kolachi";
BluetoothSerial SerialBT;
void setup() {
Serial.begin(9600); //Initialize serial
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
SerialBT.begin("Boat"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(33,OUTPUT);
pinMode(32,OUTPUT);
delay(5000);
//blue();
}
void blue(){
Serial.println("Enter wifi Name");
ab:
digitalWrite(33,HIGH);
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
ssid =SerialBT.readString();
Serial.print(ssid);
}
else {
goto ab;
}
Serial.println("Enter password");
ac:
digitalWrite(33,LOW);
digitalWrite(32,HIGH);
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
password =SerialBT.readString();
Serial.print(password);
fl=1;
}
else {
goto ac;
}
}
void battery1(){
update1:
adc_value = analogRead(35);
Serial.print("b1");
Serial.println(adc_value); // lets assume
adc_voltage = (adc_value * ref_voltage) / 4096.0;
Serial.println(adc_voltage);
if ((millis() - lastTime) > timerDelay) {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
digitalWrite(33,HIGH);
digitalWrite(32,HIGH);
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid.c_str(), password.c_str());
delay(5000);
if(WiFi.status() != WL_CONNECTED){
Serial.println("Enter correct wifi and pass");
//blue();
}
}
Serial.println("\nConnected.");
}
delay(1000);
int x = ThingSpeak.writeField(myChannelNumber, 1,adc_voltage, myWriteAPIKey);
if(x == 200){
digitalWrite(33,LOW);
digitalWrite(32,LOW);
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
goto update1;
}
lastTime = millis();
}
}
void battery2(){
update2:
adc_value = analogRead(34);
Serial.print("b2");
Serial.println(adc_value);
adc_voltage1 = (adc_value * ref_voltage) / 4096.0;
Serial.println(adc_voltage1);
if ((millis() - lastTime1) > timerDelay1) {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid.c_str(), password.c_str());
delay(5000);
if(WiFi.status() != WL_CONNECTED){
Serial.println("Enter correct wifi and pass");
// blue();
}
}
Serial.println("\nConnected.");
}
delay(1000);
int z = ThingSpeak.writeField(myChannelNumber, 2,adc_voltage1, myWriteAPIKey);
if(z == 200){
digitalWrite(33,LOW);
digitalWrite(32,LOW);
Serial.println("Channel 2 update successful.");
}
else{
Serial.println("Problem updating channel 2. HTTP error code " + String(z));
goto update2;
}
lastTime1 = millis();
}
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
char fl =SerialBT.read();
delay(5000);
if (fl=='2'){
blue();
}
}
battery1();
delay(1000);
battery2();
delay(1000);
}
i was on two different pcs when pasting
Why are you using goto?
What is wrong with the battery readings, and hopefully it does not take another 14 posts to get an answer, with your code?
Hi,
I see an awful lot of code and now you have a scaling problem.
Did you write your code in stages, getting each stage to work before going to the next, then combining them one by one and testing the outcome.
If so, then you should have some code that just reads the batteries and uses the IDE monitor to output the values.
Forget about BT and WIFi, and just check the code that measures the batteries voltages.
Tom...
The voltage readings are not exact , as on the serial monitor battery 1 reads 14.73 but true voltage is 14.2 why is this so eratic
ok will try that thanks for your advise do you know a simple formula i can use to test the voltages
Your code is a mess.
So just make a code that just reads the ADC and post it, we will work on that bit to get the readings correct as that's what you want help with.
Hi,
Can you please post a schematic of your project?
Measure the voltage at the analog inputs and check that your potential dividers are working.
Do you have a good connection at your battery gnds?
A picture(s) of your project would be good too.
Thanks.. Tom...
Hello truth is i dont know the goto ab; it was put in for me
no problem will do my best to show you
Standalone read the battery code
#include "sdkconfig.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h"
#include <driver/adc.h>
INSTALL THIS library, https://www.arduino.cc/reference/en/libraries/simplekalmanfilter/
#include <SimpleKalmanFilter.h>
////
void setup()
{
adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_DB_11);// using GPIO 35
//
xTaskCreatePinnedToCore( fReadBattery, "fReadBattery", 4000, NULL, 3, NULL, 1 );
}
////
void fReadBattery( void * parameter )
{
float adcValue = 0.0f;
notice my resistos values difeer from your.
Use 10K for R@
const float r1 = 50500.0f; // R1 in ohm, 50K
const float r2 = 10000.0f; // R2 in ohm, 10k potentiometer
float Vbatt = 0.0f;
int printCount = 0;
float vRefScale = (3.3f / 4096.0f) * ((r1 + r2) / r2);
uint64_t TimePastKalman = esp_timer_get_time(); // used by the Kalman filter UpdateProcessNoise, time since last kalman calculation
SimpleKalmanFilter KF_ADC_b( 1.0f, 1.0f, .01f );
TickType_t xLastWakeTime = xTaskGetTickCount();
const TickType_t xFrequency = 1000; //delay for mS
for (;;)
{
adc1_get_raw(ADC1_CHANNEL_7); //read and discard
adcValue = float( adc1_get_raw(ADC1_CHANNEL_7) ); //take a raw ADC reading
KF_ADC_b.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
adcValue = KF_ADC_b.updateEstimate( adcValue ); // apply simple Kalman filter
Vbatt = adcValue * vRefScale;
xSemaphoreTake( sema_CalculatedVoltage, portMAX_DELAY );
CalculatedVoltage = Vbatt;
xSemaphoreGive( sema_CalculatedVoltage );
printCount++;
if ( printCount == 3 )
{
log_i( "Vbatt %f", Vbatt );
printCount = 0;
}
TimePastKalman = esp_timer_get_time(); // time of update complete
xLastWakeTime = xTaskGetTickCount();
vTaskDelayUntil( &xLastWakeTime, xFrequency );
//log_i( "fReadBattery %d", uxTaskGetStackHighWaterMark( NULL ) );
}
vTaskDelete( NULL );
}
////////
void loop() { }
Install the SimpleKalman filter library.
truth is i am a complete newbie on this so just me writing or trying to write the code for to read the ADC will be hard so any help would be appreciated
ok will do thanks
we are getting this error xSemaphoreTake( sema_CalculatedVoltage, portMAX_DELAY );
do i have to install the resistors before verifying the code