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
Related
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.
I'm trying to get this Code for the AMT22 Encoder Using a ESP32C3-DevModule to work but the Arduino IDE is erroring me that "HSPI" is not declared in the scope any suggestions on what it should be declared as?
It also is Erroring for the line below
begin(_pinCLCK, _pinMISO, _pinMOSI, _pinSS);
but it should be pulling from the AMT22.h library those values.
#include "AMT22.h"
#include <stdlib.h>
#include <SPI.h>
SPIClass * AMT22::encoder = NULL; // this must be here -> see https://stackoverflow.com/questions/39336029/arduino-accessing-static-variable-in-the-classs-static-method
AMT22::AMT22(const byte CLCK,
const byte MISO,
const byte MOSI,
const byte SS) {
_pinCLCK = CLCK;
_pinMISO = MISO;
_pinMOSI = MOSI;
_pinSS = SS;
}
void AMT22::Begin() {
if (AMT22::encoder == NULL) {
AMT22::encoder = new SPIClass(HSPI);
AMT22::encoder -> setClockDivider(SPI_CLOCK_DIV32);
AMT22::encoder -> begin(_pinCLCK, _pinMISO, _pinMOSI, _pinSS); // SCLK, MISO, MOSI, SS
}
This is from the AMT22.h Library
private:
AMT22::Position getPositionSingle();
AMT22::Position getPositionMulti();
void setCSLine(uint8_t releaseLine);
uint8_t spiWriteRead(uint8_t sendByte, uint8_t releaseLine);
AMT22::Position position;
byte _pinMISO = 12;
byte _pinMOSI = 13;
byte _pinCLCK = 14;
byte _pinSS = 15;
// uninitalised pointers to SPI
objects
static SPIClass *encoder;
};
#endif
The code is intended to Get a Multiturn Function from the encoder- i.e. When the Motor spins the encoder will be able to serial print the amount of rotations counting upwards and downwards.
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);
}
I'm trying to code a GSM caller number receiver. When I (as the phone answerer) answer the phone it should print out the caller number.
I have trouble finding the right AT command for receiving the caller number. I tried AT+CLIP=1\r and on the loop +CLIP, but with no success.
Here is my code:
#include <GSMSim.h>
#include <SoftwareSerial.h>
#define RX 7
#define TX 8
#define RESET 2
#define BAUD 9600
GSMSim gsm;
SoftwareSerial mySerial = SoftwareSerial(RX, TX);
/*
* Also you can this types:
* GSMSim gsm(RX, TX);
* GSMSim gsm(RX, TX, RESET);
* GSMSim gsm(RX, TX, RESET, LED_PIN, LED_FLAG);
*/
void setup() {
Serial.begin(9600);
Serial.println("GSMSim Library - Call Example");
Serial.println("");
delay(1000);
gsm.start(); // baud default 9600
mySerial.read();
mySerial.print("AT+CLIP=1\r");
}
void loop() {
Serial.println(gsm.callStatus());
gsm.callAnswer();
Serial.println("Number:");
Serial.println(mySerial.print("+CLIP"));
delay(1000);
}
I got It working by using mySerial, (ATDevice) read function and using command function to accualy print it out, anyone who looks up how it work, here Is my code
#include <GSMSim.h>
#include <SoftwareSerial.h>
#include <string.h>
#define RX 7
#define TX 8
#define RESET 2
#define BAUD 9600
char outArray;
char inData[20];
char inChar=-1;
byte index = 0;
char * pch;
char* substring(char*, int, int);
GSMSim gsm;
SoftwareSerial ATDevice = SoftwareSerial(RX, TX);
/*
* Also you can this types:
* GSMSim gsm(RX, TX);
* GSMSim gsm(RX, TX, RESET);
* GSMSim gsm(RX, TX, RESET, LED_PIN, LED_FLAG);
*/
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
ATDevice.begin(9600);
command("AT+CLIP=1",1000);
delay(1000);
}
String command(const char *toSend, unsigned long milliseconds) {
String result;
ATDevice.println(toSend);
unsigned long startTime = millis();
Serial.print("Return: ");
while (millis() - startTime < milliseconds) {
if (ATDevice.available()) {
char c = ATDevice.read();
result += c; // append to the result string
}
}
Serial.println(); // new line after timeout.
return result;
}
void loop() {
command("+CLIP",1000);
delay(2000);
}
I have some problem with my own arduino library. Compiler does not recognize my class Platform and says: "error: 'Platform' does not name a type".
Here is the main program code:
#include <Platform.h>
#define MOVE_FORWARD 0xFF
#define MOVE_BACKWARD 0xF0
// Error 'Platform' does not name a type
Platform plt(13, 14, 15);
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.read() == MOVE_FORWARD)
plt.move(5);
if (Serial.read() == MOVE_BACKWARD)
plt.move(-5);
}
Here is the Platform.h code:
#ifndef PLATFORM_H
#define PLATFORM_H
#include <arduino.h>
#include <Motor.h>
class Platform {
public:
Platform(int input_1, int input_2, int enable); // Pins for L293D
void move(int distance);
private:
Motor *m_motors; // All motors connected to one L293D
};
#endif
And implementation of Platform:
#include "Platform.h"
Platform::Platform(int input_1, int input_2, int enable){
m_motors = new Motor(input_1, input_2, enable);
}
void Platform::move(int distance){
byte mm_delay = 100;
byte motor_power = 128;
if (distance > 0)
m_motors->forvard(motor_power);
else if (distance < 0)
m_motors->backward(motor_power);
delay(mm_delay*distance);
m_motors->stop();
}
The behavior of the compiler is pretty strange for me because the Motor library work nice and structure of Platform.h is the same as structure of Motor.h.
From above program it is clear that error report your getting because of below reason . you need to change header include file from #include <Platform.h> to include "Platform.h".