Arduino Nano Every Error: cannot convert 'boolean {aka bool}' to 'PinStatus'

hi i am very new to Arduino and I started piecing this code together with an Arduino Uno as my quick tester so I can quickly connect everything and see if its working. I wanted to upload the exact same code to my Arduino Nano Every but it gives me an error. Im using a Motor Driver maybe that's the problem?

#include <Servo.h>

int buttonStart = 0;

int buttonMiddle = 0;

int buttonEnd = 0;

// Setup pins
int standBy = 10;

// Motor A
int PWMA = 3;   // PWM Speed Control
int AIN1 = 9;   // Direction pin 1
int AIN2 = 8;   // Direction pin 2

// Motor B
int PWMB = 5;   // PWM Speed Control
int BIN1 = 11;  // Direction pin 1
int BIN2 = 12;  // Direction pin 2

Servo servo_13;

void setup()
{
  pinMode(2, INPUT);
  pinMode(1, INPUT);
  pinMode(4, INPUT);
  servo_13.attach(13, 500, 2500);

  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);

  // Setup Pins as OUTPUT
  pinMode(standBy, OUTPUT);

  // Motor A
  pinMode(PWMA, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);

  // Motor B
  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);

  Serial.begin(19200);
  Serial.println("I Did it");
}

void loop()
{
 
  buttonStart = digitalRead(2);
  buttonMiddle = digitalRead(1);
  buttonEnd = digitalRead(4);
  servo_13.write(0);
  if (buttonStart == HIGH) {
    servo_13.write(90);
    delay(5000); 
    forward(128);   // Move forward
  }
  if (buttonMiddle == HIGH) {
     delay(30000); 
     reverse(255);   // Move in reverse
  }
  if (buttonEnd == HIGH) {
  stop();
  }
  servo_13.write(0);
}

/*
 * Functions
 * *****************************************************
 */

void turnLeft(int spd)
{
  runMotor(0, spd, 0);
  runMotor(1, spd, 1);
}

void turnRight(int spd)
{
  runMotor(0, spd, 1);
  runMotor(1, spd, 0);
}

void forward(int spd) 
{
  runMotor(0, spd, 0);
  runMotor(1, spd, 0);
}

void reverse(int spd)
{
  runMotor(0, spd, 1);
  runMotor(1, spd, 1);
}

void runMotor(int motor, int spd, int dir)
{
  digitalWrite(standBy, HIGH); // Turn on Motor

  boolean dirPin1 = LOW;
  boolean dirPin2 = HIGH;

  if(dir == 1) {
    dirPin1 = HIGH;
    dirPin2 = LOW;
  }

  if(motor == 1) {
    digitalWrite(AIN1, dirPin1);
    digitalWrite(AIN2, dirPin2);
    analogWrite(PWMA, spd);
  } else {
    digitalWrite(BIN1, dirPin1);
    digitalWrite(BIN2, dirPin2);
    analogWrite(PWMB, spd);
  }
  
}

void stop() {
  digitalWrite(standBy, LOW);
}

the error message says: cannot convert 'boolean {aka bool}' to 'PinStatus' for argument '2' to 'void digitalWrite(pin_size_t, PinStatus)'
if you know what to to could you answer it in the most dumbed down way, I read a similar post with a similar problem but I didn't understand anything about it

Don't use boolean, it's a nonstandard type alias, use bool instead. However, in this case, also don't use bool for pin states, use PinStatus:

  PinStatus dirPin1 = LOW;
  PinStatus dirPin2 = HIGH;

Pieter

With the official core for the Nano Every, you can't pass booleans as the second argument to digitalWrite. They do this moronic thing with PinStatus enum for HIGH/LOW (and PinMode for the arguments to pinMode - which has the incredibly perverse effect of making PinMode(pin,value) valid code, rather than a syntax error. I spent like an hour searching for that before I found it with my own megaTinyCore, which was based on that official core. I then immediately dropped what I was doing and excised that abomination from my core so the digital I/O functions work like they do on an Uno there :stuck_out_tongue: ).

The unofficial MegaCoreX supports the ATmega4809 used on the Nano Every with "normal" digital I/O functions (as well as a bunch of other improvements); I think they have a pin mapping that matches the numbering on the Nano Every too. I use MCUdude's cores instead of the official ones for everything (either he or I maintain a core for all the AVR chips one might want to use with Arduino) MegaCoreX

DrAzzy:
With the official core for the Nano Every, you can't pass booleans as the second argument to digitalWrite. They do this moronic thing with PinStatus enum for HIGH/LOW (and PinMode for the arguments to pinMode - which has the incredibly perverse effect of making PinMode(pin,value) valid code, rather than a syntax error. I spent like an hour searching for that before I found it with my own megaTinyCore, which was based on that official core. I then immediately dropped what I was doing and excised that abomination from my core so the digital I/O functions work like they do on an Uno there :stuck_out_tongue: ).

The unofficial MegaCoreX supports the ATmega4809 used on the Nano Every with "normal" digital I/O functions (as well as a bunch of other improvements); I think they have a pin mapping that matches the numbering on the Nano Every too. I use MCUdude's cores instead of the official ones for everything (either he or I maintain a core for all the AVR chips one might want to use with Arduino) MegaCoreX

thank u for the quick response I will look into MegaCoreX and get rid of that boolean stuff

There's a bug submitted for this:

It's had quite a bit of discussion.

PieterP:
Don't use boolean, it's a nonstandard type alias, use bool instead. However, in this case, also don't use bool for pin states, use PinStatus:

  PinStatus dirPin1 = LOW;

PinStatus dirPin2 = HIGH;



Pieter

thank you I will try this as well ( can I just replace the two commands or do I have to change some other stuff)

PieterP:
Don't use boolean, it's a nonstandard type alias, use bool instead. However, in this case, also don't use bool for pin states, use PinStatus:

  PinStatus dirPin1 = LOW;

PinStatus dirPin2 = HIGH;



Pieter

please help I replaced the bool stuff with this but it says its out of scope what do I do ?

Kilian03:
please help I replaced the bool stuff with this but it says its out of scope what do I do ?

That's a different error. Please post your full code and the full error message.

PieterP:
That's a different error. Please post your full code and the full error message.

#include <Servo.h>

int buttonStart = 0;

int buttonMiddle = 0;

int buttonEnd = 0;

// Setup pins
int standBy = 10;


// Motor A
int PWMA = 3;   // PWM Speed Control
int AIN1 = 9;   // Direction pin 1
int AIN2 = 8;   // Direction pin 2

// Motor B
int PWMB = 5;   // PWM Speed Control
int BIN1 = 11;  // Direction pin 1
int BIN2 = 12;  // Direction pin 2

Servo servo_13;

void setup()
{
  pinMode(2, INPUT);
  pinMode(6, INPUT);
  pinMode(4, INPUT);
  servo_13.attach(13, 500, 2500);


  // Setup Pins as OUTPUT
  pinMode(standBy, OUTPUT);

  // Motor A
  pinMode(PWMA, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);

  // Motor B
  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);

  Serial.begin(19200);
  Serial.println("I Did it");
}

void loop()
{
 
  buttonStart = digitalRead(2);
  buttonMiddle = digitalRead(6);
  buttonEnd = digitalRead(4);
  
  if (buttonStart == HIGH) {
    servo_13.write(90);
    delay(5000); 
    forward(128);   // Move forward
  }
  if (buttonMiddle == HIGH) {
     delay(30000); 
     reverse(255);   // Move in reverse
  }
  if (buttonEnd == HIGH) {
  stop();
  servo_13.write(0);
  }
 
}

/*
 * Functions
 * *****************************************************
 */


void forward(int spd) 
{
  runMotor(0, spd, 0);
  runMotor(1, spd, 0);
}

void reverse(int spd)
{
  runMotor(0, spd, 1);
  runMotor(1, spd, 1);
}

void runMotor(int motor, int spd, int dir)
{
  digitalWrite(standBy, HIGH); // Turn on Motor

  //boolean dirPin1 = LOW;
  //boolean dirPin2 = HIGH;
  
  PinStatus dirPin1 = LOW;
  PinStatus dirPin2 = HIGH;

  if(dir == 1) {
    dirPin1 = HIGH;
    dirPin2 = LOW;
  }

  if(motor == 1) {
    digitalWrite(AIN1, dirPin1);
    digitalWrite(AIN2, dirPin2);
    analogWrite(PWMA, spd);
  } else {
    digitalWrite(BIN1, dirPin1);
    digitalWrite(BIN2, dirPin2);
    analogWrite(PWMB, spd);
  }
  
}

void stop() {
  digitalWrite(standBy, LOW);
}

error message:

[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino: In function 'void runMotor(int, int, int)':[/color]
[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino:98:3: error: 'PinStatus' was not declared in this scope[/color]
[color=#da5b4a]PinStatus dirPin1 = LOW;[/color]
[color=#da5b4a]^~~~~~~~~[/color]
[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino:99:13: error: expected ';' before 'dirPin2'[/color]
[color=#da5b4a]PinStatus dirPin2 = HIGH;[/color]
[color=#da5b4a]^~~~~~~[/color]
[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino:102:5: error: 'dirPin1' was not declared in this scope[/color]
[color=#da5b4a]dirPin1 = HIGH;[/color]
[color=#da5b4a]^~~~~~~[/color]
[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino:103:5: error: 'dirPin2' was not declared in this scope[/color]
[color=#da5b4a]dirPin2 = LOW;[/color]
[color=#da5b4a]^~~~~~~[/color]
[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino:107:24: error: 'dirPin1' was not declared in this scope[/color]
[color=#da5b4a]digitalWrite(AIN1, dirPin1);[/color]
[color=#da5b4a]^~~~~~~[/color]
[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino:108:24: error: 'dirPin2' was not declared in this scope[/color]
[color=#da5b4a]digitalWrite(AIN2, dirPin2);[/color]
[color=#da5b4a]^~~~~~~[/color]
[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino:111:24: error: 'dirPin1' was not declared in this scope[/color]
[color=#da5b4a]digitalWrite(BIN1, dirPin1);[/color]
[color=#da5b4a]^~~~~~~[/color]
[color=#da5b4a]/tmp/641214848/Schuh_Code/Schuh_Code.ino:112:24: error: 'dirPin2' was not declared in this scope[/color]
[color=#da5b4a]digitalWrite(BIN2, dirPin2);[/color]
[color=#da5b4a]^~~~~~~[/color]
[color=#da5b4a]exit status 1[/color]

PieterP:
That's a different error. Please post your full code and the full error message.

nevermind I just noticed I had the normal Arduino Nano selected, after changing that back to the nano Every it doesn't show an error anymore

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