Error Help for BD-1

I am building a Star Wars BD-1 droid. I am done with the build, the wiring, and now have hit a snag in the coding. Someone on the Build Boards shared this sketch for an ESP32. I have loaded all the appropriate libraries. But, when I compile, I get this error. I only understand basic coding language, so this is Greek to me--

Here is the error:

C:\Users\mjt82\OneDrive\Documents\Arduino\DS-1_rev103\DS-1_rev103.ino: In function 'void setup()':
C:\Users\mjt82\OneDrive\Documents\Arduino\DS-1_rev103\DS-1_rev103.ino:252:28: error: invalid conversion from 'void (*)(const uint8_t*, const uint8_t*, int)' {aka 'void (*)(const unsigned char*, const unsigned char*, int)'} to 'esp_now_recv_cb_t' {aka 'void (*)(const esp_now_recv_info*, const unsigned char*, int)'} [-fpermissive]
  252 |   esp_now_register_recv_cb(OnDataRecv);
      |                            ^~~~~~~~~~
      |                            |
      |                            void (*)(const uint8_t*, const uint8_t*, int) {aka void (*)(const unsigned char*, const unsigned char*, int)}
In file included from C:\Users\mjt82\OneDrive\Documents\Arduino\DS-1_rev103\DS-1_rev103.ino:11:
C:\Users\mjt82\AppData\Local\Arduino15\packages\esp32\tools\esp32-arduino-libs\idf-release_v5.4-2f7dcd86-v1\esp32/include/esp_wifi/include/esp_now.h:159:54: note:   initializing argument 1 of 'esp_err_t esp_now_register_recv_cb(esp_now_recv_cb_t)'
  159 | esp_err_t esp_now_register_recv_cb(esp_now_recv_cb_t cb);
      |                                    ~~~~~~~~~~~~~~~~~~^~
exit status 1

Compilation error: invalid conversion from 'void (*)(const uint8_t*, const uint8_t*, int)' {aka 'void (*)(const unsigned char*, const unsigned char*, int)'} to 'esp_now_recv_cb_t' {aka 'void (*)(const esp_now_recv_info*, const unsigned char*, int)'} [-fpermissive]

This is the sketch.

//Original software created by Andrew Donatelli
//Created: March 8, 2020
//Modded by Darren Serool

#include <Wire.h>
#include <Arduino.h>
#include <DFPlayerMini_Fast.h>
#include <Adafruit_PWMServoDriver.h>
#include <OneButton.h>
#include "Buttons.h"
#include <esp_now.h>
#include <WiFi.h>

Adafruit_PWMServoDriver pwmBase = Adafruit_PWMServoDriver(0x40);
Adafruit_PWMServoDriver pwmMain = Adafruit_PWMServoDriver(0x41);

// REPLACE WITH YOUR ESP RECEIVER'S MAC ADDRESS
uint8_t broadcastAddress1[] = { 0x94, 0xE6, 0x86, 0xA8, 0x1B, 0x28 };

HardwareSerial mySoftwareSerial(1);
DFPlayerMini_Fast myDFPlayer;

unsigned long moveServoWait = millis();
unsigned long replyWait = millis();
unsigned long replyWaitTime = millis();

OneButton switchButton1(15, true);
OneButton switchButton2(2, true);
OneButton switchButton3(0, true);
OneButton switchButton4(4, true);

int incomingByte = 9999;
uint16_t RunMode = 0;

long timer = 0;

int DelayStep;
int newMood;


#define lTiltHome 375
uint16_t lTiltPos = lTiltHome;
uint16_t lTiltPrevPos = lTiltHome;

#define rTiltHome 230
uint16_t rTiltPos = rTiltHome;
uint16_t rTiltPrevPos = rTiltHome;

#define turnHome 400
uint16_t turnPos = turnHome;
uint16_t turnPrevPos = turnHome;

#define earHome 300
uint16_t earPos = earHome;
uint16_t earPrevPos = earHome;

#define holoHome 350
uint16_t holoPos = holoHome;
uint16_t holoPrevPos = holoHome;

#define aperHome 300
uint16_t aperPos = aperHome;
uint16_t aperPrevPos = aperHome;

#define bodyHome 350
uint16_t bodyPos = bodyHome;
uint16_t bodyPrevPos = bodyHome;

#define neckHome 400
uint16_t neckPos = neckHome;
uint16_t neckPrevPos = neckHome;

#define lLegHome 325
uint16_t lLegPos = lLegHome;
uint16_t lLegPrevPos = lLegHome;

#define rLegHome 335
uint16_t rLegPos = rLegHome;
uint16_t rLegPrevPos = rLegHome;

//set delays
uint16_t earDelay;
uint16_t earDelayCount;
uint16_t holoDelay;
uint16_t holoDelayCount;
uint16_t aperDelay;
uint16_t aperDelayCount;
uint16_t bodyDelay;
uint16_t bodyDelayCount;
uint16_t neckDelay;
uint16_t neckDelayCount;
uint16_t turnDelay;
uint16_t turnDelayCount;
uint16_t rTiltDelay;
uint16_t rTiltDelayCount;
uint16_t lTiltDelay;
uint16_t lTiltDelayCount;
uint16_t lLegDelay;
uint16_t lLegDelayCount;
uint16_t rLegDelay;
uint16_t rLegDelayCount;
uint8_t servonum = 0;

unsigned long volTimer = 0;
int volControl;
int volPrevControl = 15;
int volCounter = 0;
int volLevel = 3;
int inputPin = 5;    // choose the input pin (for PIR sensor)
int pirState = LOW;  // we start, assuming no motion detected
int val = 0;         // variable for reading the pin status
int mood;
int droid;
int active;
int response;

bool bEars = false;
bool bHolo = false;
bool bAper = false;
bool bBody = false;
bool bNeck = false;
bool bTurn = false;
bool bRTilt = false;
bool bLTilt = false;
bool bLegs = false;
bool bProjector = false;
bool bDance = false;

typedef struct test_struct {
  int mood;
  int droid;
  int active;
} test_struct;

test_struct test;

test_struct myData;

esp_now_peer_info_t peerInfo;

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  char macStr[18];
  //Serial.print("Packet to: ");
  // Copies the sender mac address to a string
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  //Serial.print(macStr);
  //Serial.print(" send status:\t");
  //Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

//callback function that will be executed when data is received
void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
}

void setup() {
  pinMode(inputPin, INPUT);  // declare sensor as input

  mySoftwareSerial.begin(9600, SERIAL_8N1, 18, 19);  // speed, type, RX, TX
  Serial.begin(115200);

  myDFPlayer.begin(mySoftwareSerial);

  myDFPlayer.volume(10);  //Set volume value (0~30).

  pwmMain.begin();
  pwmBase.begin();

  //pwmMain.setOscillatorFrequency(26500000);
  pwmMain.setPWMFreq(50);  // Analog servos run at ~50 Hz updates
  pwmBase.setPWMFreq(50);
  delay(10);

  //start serial connection
  randomSeed(analogRead(7));

  myDFPlayer.wakeUp();

  //Begin pwmMain **********
#define pwmMainAddr 1
#define servoEar1 0
#define servoEar2 1
#define servoRTilt 2
#define servoLTilt 3
#define servoHeadTurn 5
#define servoNeck 6
#define servoBody 7
#define aperb 8
#define aperg 9
#define aperr 10
#define servoAperature 11
#define holob 12
#define holog 13
#define holor 14
#define servoHolo 15
  //End pwmMain **********

  //Begin pwmBase **********
#define pwmBaseAddr 0
#define servoLegL 0
#define servoLegR 1
  //End pwmBase **********

  // servo extents
#define earMin 200
#define earMax 400
#define holoMin 280
#define holoMax 420
#define aperMin 120
#define aperMax 460
#define bodyMin 270
#define bodyMax 430
#define neckMin 300
#define neckMax 500
#define turnMin 300
#define turnMax 500
#define lTiltMin 225
#define lTiltMax 525
#define rTiltMin 80
#define rTiltMax 380
#define lLegMin 245
#define lLegMax 305
#define rLegMin 255
#define rLegMax 315

  //chance for each servo to move
#define earChance 1500
#define holoChance 2500
#define aperChance 800
#define bodyChance 1500
#define neckChance 2000
#define turnChance 1500
#define rTiltChance 1800
#define lTiltChance 1800
#define legsChance 4000  //This servo has to work very hard.  Don't over do it.

  //delay paramaters for servo speed - less delay and more steps is faster
#define DelayMin 1   //minumum delay between servo steps - lower is faster
#define DelayMed 4   //medium delay between servo steps - servos moving heavier parts should have a lower top speed
#define DelayMax 10  //maximum delay between servo steps - higher is slower
  DelayStep = 10;    //number of steps in each loop - this affects the speed of all servos - higher is faster

  WiFi.mode(WIFI_STA);

  if (esp_now_init() != ESP_OK) {
    return;
  }

  esp_now_register_recv_cb(OnDataRecv);

  esp_now_register_send_cb(OnDataSent);

  // register peer
  peerInfo.channel = 0;
  peerInfo.encrypt = false;
  // register first peer
  memcpy(peerInfo.peer_addr, broadcastAddress1, 6);
  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    return;
  }
  myData.droid = 1;
  myData.mood = 2;
  myData.active = 1;

  // Switches
  switchButton1.setClickTicks(300);
  switchButton1.setPressTicks(600);
  switchButton1.attachClick(switch1_Click);
  switchButton1.attachDoubleClick(switch1_Doubleclick);
  switchButton1.attachLongPressStart(switch1_LongPressStart);

  switchButton2.setClickTicks(300);
  switchButton2.setPressTicks(600);
  switchButton2.attachClick(switch2_Click);
  switchButton2.attachDoubleClick(switch2_Doubleclick);
  switchButton2.attachLongPressStart(switch2_LongPressStart);

  switchButton3.setClickTicks(300);
  switchButton3.setPressTicks(600);
  switchButton3.attachClick(switch3_Click);
  switchButton3.attachDoubleClick(switch3_Doubleclick);
  switchButton3.attachLongPressStart(switch3_LongPressStart);

  switchButton4.setClickTicks(300);
  switchButton4.setPressTicks(600);
  switchButton4.attachClick(switch4_Click);
  switchButton4.attachDoubleClick(switch4_Doubleclick);
  switchButton4.attachLongPressStart(switch4_LongPressStart);
  // end Switch

  myDFPlayer.volume(volLevel * 5);
  delay(5000);
  myDFPlayer.play(10);

  CenterAll();
}

// BEGIN LOOP ***************
void loop() {
  switchButton1.tick();
  switchButton2.tick();
  switchButton3.tick();
  switchButton4.tick();

  switch (RunMode) {

    case RunMotion:
      PIR();
      break;

    case RunVoice:
      Voice();
      break;

    case RunWIFI:
      WIFI();
      break;
  }
}
// END LOOP ***********************

Thank you for any/all feedback. Myself and BD-Y (aka Betty) appreciate you.
-Lindsey

probably problem with update from ESP32 core V2.x to V3.X - see Migration from 2.x to 3.0

try replacing the callback

void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {

with

void OnDataRecv(const esp_now_recv_info_t* mac, const unsigned char* incomingData, int len) {

Thank you! Thank you! Thank you! It compiled!
Now let's see if Betty works!

And, after a little bit of blue smoke (turns out DFPlayer Mini wants LESS than 5v), everything hooks up. And then... NADA. NOTHING. Serial monitor says this:

E (5842) i2c.master: i2c_master_multi_buffer_transmit(1186): I2C transaction failed
E (5850) i2c.master: I2C hardware NACK detected
E (5854) i2c.master: I2C transaction unexpected nack detected
E (5859) i2c.master: s_i2c_synchronous_transaction(924): I2C transaction failed
E (5866) i2c.master: i2c_master_multi_buffer_transmit(1186): I2C transaction failed
E (5874) i2c.master: I2C hardware NACK detected
E (5878) i2c.master: I2C transaction unexpected nack detected
E (5883) i2c.master: s_i2c_synchronous_transaction(924): I2C transaction failed
E (5890) i2c.master: i2c_master_multi_buffer_transmit(1186): I2C transaction failed
E (5898) i2c.master: I2C hardware NACK detected
E (5902) i2c.master: I2C transaction unexpected nack detected
E (5907) i2c.master: s_i2c_synchronous_transaction(924): I2C transaction failed
E (5914) i2c.master: i2c_master_multi_buffer_transmit(1186): I2C transaction failed

I am not using a pwmBase (Adafruit_PWMServoDriver pwmBase = Adafruit_PWMServoDriver(0x40);). The joints at her ankles are too weak, and will crack if I try to animate them as is. Therefore, I bypassed this servo driver and went straight to pwmMain.
Could that be my problem? If so (remember, Arduino kindergartner here), do I just go through and delete any mention of the pwmBase?

before attempting the program of post 1 did you test each device etc in a separate program to ensure it worked?
how do you power the system? upload a schematic?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.