Prima volta con Arduino - Arduino: 1.8.13 (Windows 10), Board: "Arduino Nano, ATmega328P"

Cosa hai modificato?

Perché, di base, NON usa la libreria Adafruit per il display, ma una libreria diversa (quella di Bodmer) che occorre scaricare ... :roll_eyes:

Vuoi dire che quella libreria si mangia così tanta memoria ?

Guglielmo

Si cavolo, è proprio colpa della libreria di Bodmer ... che sarà sicuramente più veloce ed ottimizzata, ma si mangia l'ira di Dio di memoria ...

Modificando per usare la libreria di Adafruit ottengo anche io:

Sketch uses 25778 bytes (83%) of program storage space. Maximum is 30720 bytes.
Global variables use 941 bytes (45%) of dynamic memory, leaving 1107 bytes for local variables. Maximum is 2048 bytes.

Un po' più di te ... hai toccato qualche altra cosa?

Guglielmo

@max1947: scarica questo .zip: motor.zip (22.5 KB) , scompattalo e compila moror.ino ... non dovrebbe dare errori, che poi realmente funzioni è un'altro paio di maniche ... in config.h ci sono tanti di quei parametri da configurare che ... :roll_eyes:

Ah, se ti da errori, è perché probabilmente, dal "Library Manager" dell'IDE devi installare le librerie macanti (es. quelle di Adafruit) ... e ringrazia Maurotec per aver trovato un modo per compilare :wink:

Guglielmo

Questa? Se si legge nella presentazione le prime parole sono:

An Arduino IDE compatible graphics and fonts library for 32 bit processors. <

Ciao, Ale.

No, QUESTA che, nel progetto, è messa come libreria consigliata per la sua velocità ...

The library has been tested with the UNO, Mega (ATmega328 or ATmega2560 processor) and the Leonardo compatible boards (ATmega32u4 processor).

... però, probabilmente, bisogna studiarsi tutto il progetto e configurare bene tutte le varie cose, perché, è scritto:

The library contains proportional fonts, different sizes can be enabled/disabled at compile time to optimise the use of FLASH memory.

... quindi, probabilmente, di base include troppa roba e bisogna mettersi li, a seconda delle proprie esigenze a configurare tutte le parti.

Come già indicato ... non esattamente un progetto per "iniziandi" (quale è il OP).

Guglielmo

... e basta guardare le opzioni che bisogna sistemare nel config.h per adattarlo a ciò che si vuole usare:

/*
 * Author: Timo Birnschein (timo.birnschein@googlemail.com)
 * Date: 2019/11/24
 * Credits: Where they are due: https://github.com/seandepagnier is the original author of the Pypilot motor code.
 */

#ifndef __CONFIG_H__
#define __CONFIG_H__

/*You may need to modify the source code to support different hardware

adc pin0 is a resistor divider to measure voltage
             allowing up to 20 volts (10k and 560 ohm, 1.1 volt reference)
adc pin1 goes to .01/.05 ohm shunt to measure current
adc pin2 goes to 100k resistor to 5v and 10k NTC thermistor to gnd ctrl temp
adc pin3 goes to 100k resistor to 5v and 10k NTC thermistor to gnd motor temp
adc pin4 rudder sense
unused analog pins should be grounded

digital pins 4 and 5 determine the current sense as folows:
pin 4 determines range
pin 5 determines high/low current  (20A or 60A max)

D4  D5
 1   1        .05 ohm, (or .001 ohm x 50 gain)
 0   1        .01 ohm
 1   0        .0005 ohm x 50 gain
 0   0        .0005 ohm x 200 gain   *ratiometric mode


digital pin6 determines:
1 - RC pwm:
   digital pin9 pwm output standard ESC (1-2 ms pulse every 20 ms)
           pin2 esc programming input/output (with arduinousblinker script)
0 - Hbridge
   digital pin2 and pin3 for low side, pin9 and pin10 for high side


optional:digital pin7 forward fault for optional switch to stop forward travel
digital pin8 reverse fault for optional switch to stop reverse travel


Ratiometric Mode:
for D4=0 and D5=0, the adc operates over the 0-5 volt range
making it ratiometric (linearly accurate) for rudder feedback
and reduces impedance in the rudder measurement
the temperature resistors are changed to 10k and 10k ntc
voltage measurement accuracy is reduced, and the resistors used are
15k and 100k for a range of 38 volts.   Pin 12 is not used in this mode.


Pin 11 drives mosfet (560ohm and 10k resistors) for clutch engage.

If Pin 12 has 560 ohm resistor to A0, then 24 volts is supported,
this allows for measuring voltage up to 40.4 volts

D12
 1    0-20.75 volts (560 and 10k resistor)  resolution 0.02 volts
 0    0-40.4  volts (280 and 10k resistor)  resolution 0.04 volts

digital pin13 is led on when engaged


The program uses a simple protocol to ensure only
correct data can be received and to ensure that
false/incorrect or random data is very unlikely to
produce motor movement.

The input and output over uart has 4 byte packets

The first byte is the command or register, the next
two bytes is a 16bit value (signed or unsigned)
the last byte is a crc8 of the first 3 bytes

If incoming data has the correct crc for a few frames
the command can be recognized.

*/

/* vnh2sp30 is supported, but warning, I received 3 boards:
1) reverse is half power making chip very hot
2) reverse does not work
3) current sense does not work

3 out of 3 were defective, I do not recommend.

vnh2sp30  <->  arduino <->  CPC5001
+5V              5v
GND              GND
EN               D10
CS               A1
INA              D2
INB              D3
PWM              D9

If used with optical isolation (strongly recommended)
PWR+             VIN
                 5v         vcc
                 tx         rx
                 rx         tx
                 gnd        gnd
*/

enum commands {COMMAND_CODE=0xc7, RESET_CODE=0xe7, MAX_CURRENT_CODE=0x1e, MAX_CONTROLLER_TEMP_CODE=0xa4, MAX_MOTOR_TEMP_CODE=0x5a, RUDDER_RANGE_CODE=0xb6, RUDDER_MIN_CODE=0x2b, RUDDER_MAX_CODE=0x4d, REPROGRAM_CODE=0x19, DISENGAGE_CODE=0x68, MAX_SLEW_CODE=0x71, EEPROM_READ_CODE=0x91, EEPROM_WRITE_CODE=0x53};

enum results {CURRENT_CODE=0x1c, VOLTAGE_CODE=0xb3, CONTROLLER_TEMP_CODE=0xf9, MOTOR_TEMP_CODE=0x48, RUDDER_SENSE_CODE=0xa7, FLAGS_CODE=0x8f, EEPROM_VALUE_CODE=0x9a};

enum {SYNC=1, OVERTEMP_FAULT=2, OVERCURRENT_FAULT=4, ENGAGED=8, INVALID=16*1, PORT_PIN_FAULT=16*2, STARBOARD_PIN_FAULT=16*4, BADVOLTAGE_FAULT=16*8, MIN_RUDDER_FAULT=256*1, MAX_RUDDER_FAULT=256*2, CURRENT_RANGE=256*4, BAD_FUSES=256*8};


enum {CONTROLLER_TEMP, MOTOR_TEMP};

/*
 * BOARD TYPE
 */
//#define BOARD_VNH2SP30 // defined if this board is used
#define BOARD_IBT2_H_BRIDGE // defined if this board is used IBT-2 H-Bridge
//#define BOARD_RAW_H_BRIDGE // defined if a raw h-bridge is used that needs to be controlled directly

/*
 * ATTACHED SENSORS
 */
//#define DISABLE_TEMP_SENSE    // if no temp sensors avoid errors
//#define DISABLE_VOLTAGE_SENSE // if no voltage sense
//#define DISABLE_CURRENT_SENSE // if no motor current sensor is installed or used
//#define DISABLE_RUDDER_SENSE  // if no rudder sense
#define DISABLE_ENDSTOPS // if no endstops are installed we won't have a forward and reverse faults

//#define DISABLE_DEBUGGING_DISPLAY // If a debugging TFT display is attached to the controller, comment this out
#define USE_STEINHART_TEMP_SENSING // If you want to use the much slower Steinhart calculation

/*
 * Current configuration
 */
#define LOW_CURRENT // gives 2000 mA. Comment to get 4000 mA max current


// *************************************************************************************************** //
// ********************************* GENERAL CONFIGURATION VALUES ************************************ //
// *************************************************************************************************** //
#define PWM_DEADBAND 40

#define RUDDER_MIN 5000 // The minimum value at which RUDDER_MIN flag is being set
#define RUDDER_MAX 60535 // The maximum value at which RUDDER_MAX flag is being set
#define RUDDER_MIN_ADC 18300 // Your actual minimum sensor value
#define RUDDER_MAX_ADC 52950 // Your actual maximum sensor value. These two must be configured to your setup to work properly
#define TEMPERATURE_CONTROLLER_MAX 7000 // 70 deg C
#define TEMPERATURE_MOTOR_MAX 7000 // 70 deg C
#define CURRENT_MOTOR_MAX 2000 // don't allow more than 20Amps
#define SPEEDUP_SLEW_RATE 15 // Slew rate when accelerating the motor / pump / linear actuator
#define SLOWDOWN_SLEW_RATE 30 // Slew rate when decelerating the motor / pump / linear actuator


// *************************************************************************************************** //
// ********************************* Thermocouple Variables ****************************************** //
// *************************************************************************************************** //
// Check https://learn.adafruit.com/thermistor/using-a-thermistor for more info
// resistance at 25 degrees C
#define THERMISTORNOMINAL 100000 // 100k thermistor
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
// the value of the 'other' resistor
#define SERIESRESISTOR 4700 // 4.7k resistor

// *************************************************************************************************** //
// ********************************* Battery Voltage Measurement Variables *************************** //
// *************************************************************************************************** //
// Maximum input voltage on the supply pin
#define VIN_MAX 1800
// Maximum input voltage on the supply pin
#define VIN_MIN 900
// Wow the ADC is configured to measure: 0V - 5V
#define ADC_RANGE 5.0f
// Bit deapth of the ADC being used
#define BIT_DEPTH 1024.0f
// Calculated voltage separation per bit
#define V_SEPARATION ADC_RANGE / BIT_DEPTH
// Voltage divider resistor 1
#define R1_1 22000.0f
// Voltage divider resistor 2
#define R2_1 4700.0f
// Constant calculated from resistor values for simplified voltage calculation
#define RESISTOR_CONSTANT_1 (R2_1/(R1_1 + R2_1))

// *************************************************************************************************** //
// ********************************* Motor Current Measurement Variables ***************************** //
// *************************************************************************************************** //
// Maximum input voltage on the supply pin
#define A_MAX 4300
// Voltage divider resistor 1
#define R1_2 47000.0f
// Voltage divider resistor 2
#define R2_2 150000.0f
// Constant calculated from resistor values for simplified voltage calculation
#define RESISTOR_CONSTANT_2 (R2_1/(R1_1 + R2_1))

#endif

Guglielmo

Ok, NON toccando il progetto "motor" (quindi la cartella originale con tutti i files non modificati) e andando a modificare il file "User_Setup.h" della libreria di Bodmer, commentanto il caricamento in flash dei font che non vengono usati (alla fine sembrerebbe essere usato SOLO il "Font 1. Original Adafruit 8 pixel font", dato che commentando tutti gli altri compila comunque), ovvero editando e commentando le righe dalla 43 alla 47:

#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
//#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
//#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
//#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
//#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
//#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.

... si ha, in fase di compilazione:

Sketch uses 20674 bytes (67%) of program storage space. Maximum is 30720 bytes.
Global variables use 872 bytes (42%) of dynamic memory, leaving 1176 bytes for local variables. Maximum is 2048 bytes.

... che è sicuramente accettabile :slight_smile:

Ripeto ... c'è poi da capire SE il programma fa quello che il OP vuole :wink:

Guglielmo

@max1947: ... hai MOLTO lavoro da fare, ma almeno ora abbiamo capito come ridurre le dimensioni e compilare con Arduino IDE 1.8.9 ... il resto sta a te, noi non possiamo provare nulla (non abbiamo l'hardware) :wink:

Questa la cartella che contiene il progetto originale che usa la libreria di di Bodmer (più veloce rispetto a quella di Adafruit): motor.zip (22.5 KB)

... ma devi modificare un file della suddetta libreria (come spiegato nel mio post qui sopra) per riuscire a compilare e stare mella memoria del Arduino Nano.

Guglielmo

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