hi,,
i have made variometer for paragliding with nano and pressure sensor ms5611. it works very well...
i want to make small package, with digispark ( attiny85 ), but len of code is too big.
i try my best to reduce the code but it took 6618 bytes instead of 6012.
is there a way to reduce this code ?
If you know you are compiling for ATTiny85 and just using Serial, you can unclutter that code quite a bit by getting rid of all the #ifdef stuff (doesn't save space, just uncluttered)
/*
VARIO XCTRACK
arduino nano OU DIGISPARK attiny45
sensor ms5611
Based on Arduino Vario by Benjamin PERRIN 2017 / Vari'Up
Based on Arduino Vario by Jaros, 2012 and vario DFelix 2013
https://github.com/LK8000/LK8000/blob/master/Docs/LK8EX1.txt
$LK8EX1,pressure,altitude,vario,temperature,battery,*checksum
test sentence PRS, shorter but no checksum
*/
//MS5611 library by Roman Schmitz forked
#include "MS5611.h"
#include <avr/wdt.h>
MS5611 sensor;
/////////////////////////////////////////
#define USB_SPEED 115200 //serial transmision speed
#define FREQUENCY 10 // freq output in Hz
/*
these 2 sentences are available for xctrack :
LK8000 sentence : 32 chars to send
$LK8EX1,pressure,altitude,vario,temperature,battery,*checksum
PRS sentence : 10 chars to send
PRS pressure in pascal in hexadecimal format
bluetooth in 9600 bauds -> 1.25ms for a char
LK8000 : 1.25*32=40ms
PRS : 1.25*10=12.5ms
USB in 115200 bauds -> 0.08ms for a char
LK8000 : 0.08*32=2.5ms
PRS : 0.08*10=0.8ms
PRS is faster but LK8000 has checksum !
*/
void setup() {
wdt_disable();
delay(10);
Serial.begin(USB_SPEED);
wdt_enable(WDTO_1S); //enable the watchdog 1s without reset
if (sensor.connect() > 0) {
delay(1200); //for watchdog timeout
}
sensor.ReadProm(); //takes about 3ms
}
uint32_t get_time = millis();
uint32_t sum = 0;
uint8_t n = 0;
void loop(void) {
wdt_reset();
sensor.Readout(); // with OSR4096 takes about 10ms
uint32_t Pressure = sensor.GetPres();
sum += Pressure;
n += 1;
if (millis() - get_time >= 1000 / FREQUENCY) //every 100 milli-seconds send NMEA output over serial port
{
get_time = millis();
Pressure = sum / n ;
sum = 0; n = 0;
// use PRS sentence
// String str_out = String("PRS ") + String(Pressure, HEX);
// Serial.println(str_out);
Serial.print(F("PRS "));
Serial.println(Pressure,HEX);
}
}
How can that happen? If you have a string in RAM, it has to be stored in flash initially and then copied to RAM when the chip powers up, even before setup(). That can not take less space than having the same string in flash and never copying it to RAM.
Without the bootloader, you will need another arduino board to act as the programmer for your ATTiny85 and some jumpers to make the connections between the two.
ok, but with digispark ( default 16.5Mhz ), can't perform Upload Using Programmer because of compilation error. perhaps i have to modify some conf to increase to 8012bytes