Go Down

Topic: Arduino Nano Every Error: cannot convert 'boolean {aka bool}' to 'PinStatus' (Read 176 times) previous topic - next topic

Kilian03

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? 
Code: [Select]
#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 

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:
Code: [Select]
  PinStatus dirPin1 = LOW;
  PinStatus dirPin2 = HIGH;

Pieter

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 :-P ). 

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
ATTinyCore and megaTinyCore for all ATtiny, DxCore for DA/DB-series! github.com/SpenceKonde
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Kilian03

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 :-P ).

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

westfw


Kilian03

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:
Code: [Select]
 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)

Go Up