Library trying to call wire.requestFrom results in error on esp32 - arduino

I am trying to run two I2C busses on a Nano32.
#include <Wire.h>
#include "MS5837.h"
// Setup sensor 1
#define I2C_SDA_1_PIN 21
#define I2C_SCL_1_PIN 22
TwoWire I2C_1 = TwoWire(0);
MS5837 sensor_1;
// Setup sensor 2
#define I2C_SDA_2_PIN 17
#define I2C_SCL_2_PIN 16
TwoWire I2C_2 = TwoWire(1);
MS5837 sensor_2;
void setup() {
Serial.begin(115200);
Serial.println("Starting");
I2C_1.begin(I2C_SDA_1_PIN, I2C_SCL_1_PIN);
I2C_2.begin(I2C_SDA_2_PIN, I2C_SCL_2_PIN);
while (!sensor_1.init(I2C_1)) {
Serial.println("Init sensor 1 failed!");
delay(5000);
}
while (!sensor_2.init(I2C_2)) {
Serial.println("Init sensor 2 failed!");
delay(5000);
}
}
void loop() {
}
The MS5837 library comes from https://github.com/bluerobotics/BlueRobotics_MS5837_Library and is not the one that can be installed via the Arduino IDE. The reason for that is that that version does not allow the setting of the TwoWire port to use.
The issue I am facing is that I get the following error message when compiling:
In file included from c:\Users\tammo\OneDrive\Documents\Arduino\libraries\BlueRobotics_MS5837_Library\MS5837.h:41,
from c:\Users\tammo\OneDrive\Documents\Arduino\libraries\BlueRobotics_MS5837_Library\MS5837.cpp:1:
C:\Users\tammo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\Wire\src/Wire.h: In member function 'bool MS5837::init(TwoWire&)':
C:\Users\tammo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\Wire\src/Wire.h:127:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int)'
uint8_t requestFrom(int address, int size);
^~~~~~~~~~~
C:\Users\tammo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\Wire\src/Wire.h:125:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t)'
uint8_t requestFrom(uint8_t address, uint8_t size);
^~~~~~~~~~~
C:\Users\tammo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\Wire\src/Wire.h: In member function 'void MS5837::read()':
C:\Users\tammo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\Wire\src/Wire.h:127:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int)'
uint8_t requestFrom(int address, int size);
^~~~~~~~~~~
C:\Users\tammo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\Wire\src/Wire.h:125:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t)'
uint8_t requestFrom(uint8_t address, uint8_t size);
^~~~~~~~~~~
C:\Users\tammo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\Wire\src/Wire.h:127:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int)'
uint8_t requestFrom(int address, int size);
^~~~~~~~~~~
C:\Users\tammo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\Wire\src/Wire.h:125:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t)'
uint8_t requestFrom(uint8_t address, uint8_t size);
^~~~~~~~~~~
Sketch uses 273661 bytes (20%) of program storage space. Maximum is 1310720 bytes.
Global variables use 22672 bytes (6%) of dynamic memory, leaving 305008 bytes for local variables. Maximum is 327680 bytes.
I am at a loss as to how to fix this and would appreciate pointers.

Related

Trying to get a photoresistor to take an analog reading through a wire command to an EV3

Here is the part of the code we are getting the error on
//turns on the i2c commands
#include <Wire.h>
//creates a variable called SLAVE_ADDRESS and permanently sets the value to 0x04 (register #4)
#define SLAVE_ADDRESS 0x04
#define IR1 A0
#define IR2 A1
#define prnt
#define measure
#define measurea
void setup()
{
Serial.begin(9600);
//sets the address of the Arduino
Wire.begin(SLAVE_ADDRESS);
//the .onRequest command will run a function when it gets a request from the EV3.
//In this case, it will run the requestEvent function, which is defined later in the sketch.
Wire.onRequest(requestEvent);
}
int measureMap = 0;
void loop() {
int measure = analogRead(A0);
int measurea = analogRead(A1);
measureMap = map(measure, 0, 1023, 0, 63);
Serial.print(mapMeasure);
Serial.print (" ");
Serail.println(measure);
Serail.println(measure1);
}
Where we have the variable measureawe get an error saying
measurea
exit status 1
expected unqualified-id before '=' token
How to fix the error?
The problem is that you already declared measurea and measure as a define macro.
You can't make a variable with the same name.
try this:
//turns on the i2c commands
#include <Wire.h>
//creates a variable called SLAVE_ADDRESS and permanently sets the value to 0x04 (register #4)
#define SLAVE_ADDRESS 0x04
#define IR1 A0
#define IR2 A1
void setup()
{
Serial.begin(9600);
//sets the address of the Arduino
Wire.begin(SLAVE_ADDRESS);
//the .onRequest command will run a function when it gets a request from the EV3.
//In this case, it will run the requestEvent function, which is defined later in the sketch.
Wire.onRequest(requestEvent);
}
int measureMap = 0;
void loop() {
int measure = analogRead(A0);
int measurea = analogRead(A1);
measureMap = map(measure, 0, 1023, 0, 63);
Serial.print(mapMeasure);
Serial.print (" ");
Serail.println(measure);
Serail.println(measure1);
}

Library error when I run the code on Arduino IDE

I've got the folllowing errors:
In file included from C:\Users\Lenovo\OneDrive\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkApi.h:37:0,
from C:\Users\Lenovo\OneDrive\Documents\Arduino\libraries\Blynk\src/BlynkApiArduino.h:14,
from C:\Users\Lenovo\OneDrive\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp8266.h:24,
from C:\Users\Lenovo\OneDrive\Desktop\sketch_mar31a\sketch_mar31a.ino:36:
C:\Users\Lenovo\OneDrive\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:36:21: error: redefinition of 'class BlynkTimer'
#define SimpleTimer BlynkTimer
^
C:\Users\Lenovo\OneDrive\Documents\Arduino\libraries\SimpleTimer-1.0.0/SimpleTimer.h:10:7: note: in expansion of macro 'SimpleTimer'
class SimpleTimer {
^
C:\Users\Lenovo\OneDrive\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:36:21: error: previous definition of 'class BlynkTimer'
#define SimpleTimer BlynkTimer
^
C:\Users\Lenovo\OneDrive\Documents\Arduino\libraries\Blynk\src/Blynk/BlynkTimer.h:41:7: note: in expansion of macro 'SimpleTimer'
class SimpleTimer {
^
exit status 1
Eroare de compilare pentru placa NodeMCU 1.0 (ESP-12E Module).
When I used this code:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "wwnCVJrGmlkVcYrYsCq-RjO2A0C5s16t"; //Enter the Auth code which was send by Blink
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "DIGI-7v32"; //Enter your WIFI Name
char pass[] = "2UWCQ6R4"; //Enter your WIFI Password
#define DHTPIN 2 // Digital pin 4
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature
}
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, ssid, pass);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
Blynk uses an open source SimpleTimer library.
There are quite a few libraries called SimpleTimer out there - See GitHub Search Results.
If you have a different version of the library to that used by Blynk you'll probably get a compile error:
BlynkTimer.h: 36:21: error: redefinition of 'class BlynkTimer
If you use the library that Blynk uses - marcelloromani/Arduino-SimpleTimer - you will not get errors on build, and can #include <SimpleTimer.h> and use it alongside Blynk without problem.
If you are using Blynk it is advisable to use BynkTimer instead of `SimpleTimer' for the following reason:
When BlynkTimer struggles to run multiple times (due to a blocked loop), it just skips all the missed intervals, and calls your function only once. New Blynk Library Release v0.5.3 - June 2018
To make the change to your code, remove
#include <SimpleTimer.h>
and replace
SimpleTimer timer;
with
BlynkTimer timer;

call of overloaded 'begin(int)' is ambiguous

Ive got a ESP32-S2 and just try to test the circuit and the Board with this simple script.
Error Code says.
ziel_19-09-2020.ino: In function 'void setup()':
ziel_19-09-2020:85:18: error: call of overloaded 'begin(int)' is ambiguous
mcp1.begin(addr1);
^
In file included from C:\Users/Arduino\ziel_19-09-2020\ziel_19-09-2020.ino:1:
C:\Users\Arduino\libraries\Adafruit_MCP23017_Arduino_Library/Adafruit_MCP23017.h:26:8: note: candidate: 'void Adafruit_MCP23017::begin(uint8_t, TwoWire*)'
void begin(uint8_t addr, TwoWire theWire = &Wire);
^~~~~
C:\Users\Arduino\libraries\Adafruit_MCP23017_Arduino_Library/Adafruit_MCP23017.h:27:8: note: candidate: 'void Adafruit_MCP23017::begin(TwoWire)'
void begin(TwoWire *theWire = &Wire);
^~~~~
exit status 1
call of overloaded 'begin(int)' is ambiguous
The code is this
#include <Adafruit_MCP23017.h>
#include <math.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include "SPI.h"
#define BUTTON_PIN 2
#define PIXEL_PIN 6
#define PIXEL_COUNT 136
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_MCP23017 mcp1;
Adafruit_MCP23017 mcp2;
Adafruit_MCP23017 mcp3;
Adafruit_MCP23017 mcp4;
Adafruit_MCP23017 mcp5;
Adafruit_MCP23017 mcp6;
Adafruit_MCP23017 mcp7;
Adafruit_MCP23017 mcp8;
///////////////////////////////////
/////////////Settings//////////////
///////////////////////////////////
int dotcolor_1=0;
int dotcolor_2=250;
int dotcolor_3=0;
int circlecolor_1=250;
int circlecolor_2=0;
int circlecolor_3=0;
int time_hold=500;
int dtime=3;
///////////////////////////////////
/////////////Settings end//////////
///////////////////////////////////
#define addr1 0
#define addr2 1
#define addr3 2
#define addr4 3
#define addr5 4
#define addr6 5
#define addr7 6
#define addr8 7
double w=0;
double xd;
double yd;
boolean sensor_1[13];
boolean sensor_2[12];
boolean sensor_3[12];
boolean sensor_4[12];
boolean sensor_5[12];
boolean sensor_6[12];
boolean sensor_7[12];
boolean sensor_8[12];
int sen1[12];
int sen2[12];
int sen3[12];
int sen4[12];
int sen5[12];
int sen6[12];
int sen7[12];
int sen8[12];
uint16_t sensor1;
uint16_t sensor2;
uint16_t sensor3;
uint16_t sensor4;
uint16_t sensor5;
uint16_t sensor6;
uint16_t sensor7;
uint16_t sensor8;
void setup() {
strip.begin();
mcp1.begin(addr1);
mcp2.begin(addr2);
mcp3.begin(addr3);
mcp4.begin(addr4);
mcp5.begin(addr5);
mcp6.begin(addr6);
mcp7.begin(addr7);
mcp8.begin(addr8);
for(int i=0;i<=15;i++){
mcp1.pinMode(i, INPUT);
mcp2.pinMode(i, INPUT);
mcp3.pinMode(i, INPUT);
mcp4.pinMode(i, INPUT);
mcp5.pinMode(i, INPUT);
mcp6.pinMode(i, INPUT);
mcp7.pinMode(i, INPUT);
mcp8.pinMode(i, INPUT);
}
If you use #define addr1 0 the compiler can't choose between begin(pointer) and begin(int), because the value from #define could be a pointer.
If you set the I2C address as typed constant of type uint8_t, which is the type of the address parameter in the begin function with I2C address, the compiler will use the right function.
So set the addresses this way const uin8_t addr1 = 0;
Basically, the Adafruit_MCP23017 library is bad. You may need to edit the library. There are actually two begin functions that you could potentially be calling, and Arduino has no idea which one you want.
Option 1:
You could add the following line outside of setup():
#define Wire TinyWireM
and changing your begin functions to:
mcp1.begin(addr1, &Wire);
mcp2.begin(addr2, &Wire);
mcp3.begin(addr3, &Wire);
mcp4.begin(addr4, &Wire);
mcp5.begin(addr5, &Wire);
mcp6.begin(addr6, &Wire);
mcp7.begin(addr7, &Wire);
mcp8.begin(addr8, &Wire);
Option 2:
Currently, the two begin functions in the library look like this:
void begin(uint8_t addr, TwoWire *theWire = &Wire);
void begin(TwoWire *theWire = &Wire);
My recommendation above is based on the assumption that you are using the first function.
Your second option would be to remove the second function.
Remove the following from Adafruit_MCP23017.cpp (starting form line 133):
/**
* Initializes the default MCP23017, with 000 for the configurable part of the
* address
* #param theWire the I2C object to use, defaults to &Wire
*/
void Adafruit_MCP23017::begin(TwoWire *theWire) { begin(0, theWire); }
Remove the following from Adafruit_MCP23017.h (line 27):
void begin(TwoWire *theWire = &Wire);
I can further guide you in editing the library if needed

Why is the delay instruction causing a compiler error?

Compiler throw an error when I added delay(timer) in the code, timer is a const integer defined at the beginning of the code.
When I comment out the delay line, the compiler completes successfully.
4th line from the bottom
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
const int BLUE = 3; // the number of the pushbutton pin
const int GREEN = 4; // the number of the LED pin
const int RED = 5; // the number of the LED pin
const int thisPin = 4;
const int timer = 100;
// the setup function runs once when you press reset or power the board
void setup() {
// Initialize ASK Object
rf_driver.init();
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
int mesg = 0;
// Set buffer to size of expected message
uint8_t buf[8];
uint8_t buflen = sizeof(buf);
if (rf_driver.recv(buf, &buflen)) {
// Message received with valid checksum
Serial.print("Message Received: ");
Serial.println((char*)buf);
mesg = 1;
}
if (mesg == 1) {
mesg = 0;
digitalWrite(thisPin, HIGH);
//delay(timer);
digitalWrite(thisPin, LOW);
}
}
Below is the error message:
C:\Users\Swee-Chuan Khoo\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp: In member function 'setModeIdle.constprop':
C:\Users\Swee-Chuan Khoo\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:421:1: internal compiler error: Segmentation fault
}
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status
compilation terminated.
c:/program files/windowsapps/arduinollc.arduinoide_1.8.21.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano.
Downgrade AVR core to 1.6.21 as suggested by Juraj. All working properly now.
Now i can continue with the project.
Thank you everyone for the help, datafiddler, Juraj and M.R.

Publishing a value through PubSubClient

I tried the following code to publish a value using Arduino onto Mosquitto broker. The code appears to be right but then as soon as I compile/verify, the following error is thrown. What's the cause and how do I overcome this problem?
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#define CLIENTID "ArduinoSensor"
#define TOPICNAME "sensor/temperature"
#define POLLINTERVAL 120000
void callback(char topic, byte payload, unsigned int length){
//Do nothing as we are publishing ONLY.
}
byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED} ;
byte server [] = { 85, 119, 83, 194 };
EthernetClient ethClient;
PubSubClient arduinoClient(server, 1883, callback, ethClient) ;
unsigned long boardTime = 0 ;
float sensedTemperature = 0;
char charTemperature [20];
void setup(void) {
Serial.begin(9600);
//Connect to the MQTT server - test.mosquitto.org
beginConnection() ;
}
//Initialise MQTT connection
void beginConnection() {
Serial.begin(9600);
Ethernet.begin(mac) ; //using the address assigned through DHCP
int connRC = arduinoClient.connect(CLIENTID) ;
if (!connRC) {
Serial.println(connRC) ;
Serial.println("Could not connect to MQTT Server");
Serial.println("Please reset the arduino to try again");
delay(100);
exit(-1);
}
else {
Serial.println("Connected to MQTT Server...");
}
}
void loop(void) {
boardTime = millis();
if ((boardTime % POLLINTERVAL) == 0) {
getTemp();
dtostrf(sensedTemperature,5,2,charTemperature) ;
arduinoClient.publish(TOPICNAME, charTemperature) ;
}
}
void getTemp() {
// Send the command to get temperatures
delay(100);
sensedTemperature = analogRead(2); //temperature sensor at analog pin 2 on Arduino.
delay(150);
}
Error Printed:
publisher:18: error: invalid conversion from 'void (*)(char, byte, unsigned int) {aka void (*)(char, unsigned char, unsigned int)}' to 'void (*)(char*, uint8_t*, unsigned int) {aka void (*)(char*, unsigned char*, unsigned int)}' [-fpermissive]
PubSubClient arduinoClient(server, 1883, callback, ethClient) ;
C:\Users\Chetan\Documents\Arduino\libraries\PubSubClient\src/PubSubClient.h:98:4: error: initializing argument 3 of 'PubSubClient::PubSubClient(uint8_t*, uint16_t, void (*)(char*, uint8_t*, unsigned int), Client&)' [-fpermissive]
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
^
exit status 1
invalid conversion from 'void (*)(char, byte, unsigned int) {aka void (*)(char, unsigned char, unsigned int)}' to 'void (*)(char*, uint8_t*, unsigned int) {aka void (*)(char*, unsigned char*, unsigned int)}' [-fpermissive]
In file included from C:\Users\Chetan\Desktop\publisher\publisher.ino:4:0:
Any suggestions?
The error message is telling you that the signature of the callback function you are passing to the constructor is incorrect.
You have:
void callback(char topic, byte payload, unsigned int length){
It should be:
void callback(char* topic, byte* payload, unsigned int length) {
Note the * for the topic and payload arguments.

Resources