davidkingsman / split-flap

code for split-flap display
https://www.prusaprinters.org/prints/69464-split-flap-display
GNU General Public License v3.0
404 stars 41 forks source link

[Nano Every] "'ADCSRA' was not declared in this scope" #12

Closed it-escher closed 1 year ago

it-escher commented 1 year ago

So i accidentally bought an "Arduino Nano Every" instead of a regular "Arduino Nano" which apparently uses a different chip (ATMega4809).

When i try to upload/verify the "unit" sketch im getting the following error:

`D:\3D Print\SplitFlap\split-flap-master\unit\unit.ino: In function 'void loop()': unit:99:23: error: 'ADCSRA' was not declared in this scope byte old_ADCSRA = ADCSRA; ^~ D:\3D Print\SplitFlap\split-flap-master\unit\unit.ino:99:23: note: suggested alternative: 'ADC_t' byte old_ADCSRA = ADCSRA; ^~ ADC_t unit:116:5: error: 'TWCR' was not declared in this scope TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^~~~ D:\3D Print\SplitFlap\split-flap-master\unit\unit.ino:116:5: note: suggested alternative: 'TWI0' TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^~~~ TWI0 In file included from C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Interrupts.h:8:0, from C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/ArduinoAPI.h:29, from C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/Arduino.h:23, from D:\3D Print\SplitFlap\split-flap-master\unit\unit.ino:8: unit:116:16: error: 'TWEN' was not declared in this scope TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^ C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Common.h:71:25: note: in definition of macro 'bit'

define bit(b) (1UL << (b))

                     ^

D:\3D Print\SplitFlap\split-flap-master\unit\unit.ino:116:16: note: suggested alternative: 'TWI0' TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^ C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Common.h:71:25: note: in definition of macro 'bit'

define bit(b) (1UL << (b))

                     ^

unit:116:28: error: 'TWIE' was not declared in this scope TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^ C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Common.h:71:25: note: in definition of macro 'bit'

define bit(b) (1UL << (b))

                     ^

D:\3D Print\SplitFlap\split-flap-master\unit\unit.ino:116:28: note: suggested alternative: 'TWI0' TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^ C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Common.h:71:25: note: in definition of macro 'bit'

define bit(b) (1UL << (b))

                     ^

unit:116:40: error: 'TWEA' was not declared in this scope TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^ C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Common.h:71:25: note: in definition of macro 'bit'

define bit(b) (1UL << (b))

                     ^

D:\3D Print\SplitFlap\split-flap-master\unit\unit.ino:116:40: note: suggested alternative: 'TWI0' TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^ C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Common.h:71:25: note: in definition of macro 'bit'

define bit(b) (1UL << (b))

                     ^

unit:116:52: error: 'TWINT' was not declared in this scope TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^ C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Common.h:71:25: note: in definition of macro 'bit'

define bit(b) (1UL << (b))

                     ^

D:\3D Print\SplitFlap\split-flap-master\unit\unit.ino:116:52: note: suggested alternative: 'TWI_t' TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT); ^ C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\cores\arduino/api/Common.h:71:25: note: in definition of macro 'bit'

define bit(b) (1UL << (b))

                     ^

Using library Wire at version 1.0 in folder: C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\libraries\Wire Using library Stepper at version 1.1.3 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries\Stepper Using library EEPROM at version 2.0 in folder: C:\Users\49160\Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.7\libraries\EEPROM exit status 1 'ADCSRA' was not declared in this scope `

Is there a way to rewrite / adapt the code for this processor by maybe "just" chaning the variable names of the registers or will this be a futile attempt and im better of just buying a regular Nano instead?

Greetings from Germany.

davidkingsman commented 1 year ago

The code to send the Nano to sleep is very specific to the ATMEGA 328p chip. Try removing the following code:

 if (currentMillis - previousMillis >= WAIT_TIME) {
    byte old_ADCSRA = ADCSRA;
    // disable ADC
    ADCSRA = 0;
    set_sleep_mode (SLEEP_MODE_PWR_DOWN);
    sleep_enable();
#ifdef serial
    digitalWrite (LED_BUILTIN, LOW); // shuts off LED when starting to sleep, for debugging
#endif
    sleep_cpu ();
#ifdef serial
    digitalWrite (LED_BUILTIN, HIGH); // turns on LED when waking up, for debugging
#endif
    sleep_disable();
    previousMillis = currentMillis; //reset sleep counter
    ADCSRA = old_ADCSRA;

    // release TWI bus
    TWCR = bit(TWEN) | bit(TWIE) | bit(TWEA) | bit(TWINT);

    // turn it back on again
    Wire.begin (i2cAddress);
  }  // end of time to sleep

You could find a way to send the 4809 to sleep or live with the higher power consumption.

it-escher commented 1 year ago

Thanks, that works for now!

Im gonna look into finding a way to rewrite this section for the Nano Every and might do a pull request if i succeed.