nerdralph / picoCore

size-optimized Arduino/Wiring core for tiny AVR MCUs
MIT License
28 stars 4 forks source link

Interesting development #1

Open RalphBacon opened 4 years ago

RalphBacon commented 4 years ago

I'm using the MicroCore but this PicoCore sounds interesting.

Will it support all the Arduino language constructs? Rhetorical question, I shall find out in due course,no doubt. When it's done I'll put it on my Tiny13 with my Fridge Alarm sketch (to which I still must add your "touch" code , rather than as a standalone sketch).

If could let me know when you think you have a 'beta' version that would be great.

nerdralph commented 4 years ago

I just released v0.2-beta. https://github.com/nerdralph/picoCore/releases

Try downloading it and extract it into your Arduino/hardware folder. The only major thing not implemented yet is Serial.

RalphBacon commented 4 years ago

HI Ralph, I used my ATTiny13 Fridge Alarm sketch as my test bed (with Serial removed, for now).

With PicoCore v0.2 it compiled as: C:/sloeber-workspace/ATTiny13_Fridge_Alarm/Release/ATTiny13_Fridge_Alarm.elf : section size addr .text 550 0 .data 2 8388704 .bss 2 8388706 .comment 17 0 I have not actually uploaded the code to an ATTiny13 to test it still works!

Using MicroCore, I get: C:/sloeber-workspace/ATTiny13_Fridge_Alarm/Release/ATTiny13_Fridge_Alarm.elf : section size addr .text 572 0 .data 2 8388704 .bss 2 8388706

Just for comparison, WITH Serial enabled, MicroCore gives me: section size addr .text 734 0 .data 24 8388704 .bss 2 8388728

So about 162 bytes of code for Serial.print/println.

Once you have Serial implemented (I would think OUTPUT only would be good enough?) I'll re-enable Serial and give it another go.

So far, so good! Regards, Ralph S B.

nerdralph commented 4 years ago

Do you have the code posted? All I could find was the fridge alarm challenge code. https://github.com/RalphBacon/177-ATTiny13-Fridge-Door-Alarm-Challenge With Serial removed, I got a flash size of 660 bytes. Using picoCore's delay() instead of _delay_ms reduced the size to 558 bytes.

nerdralph commented 4 years ago

While testing with your door alarm code, I found a bug in picoCore related to sketches that use their own main. I should have a fix pushed later today. I reviewed your code, and found lots of ways to improve it. The most significant change is getting rid of the global variables. Globals should be generally avoided in any C/C++ code. In the process, I cleaned up things like the doorOpen and doorClose functions so they are more readable and follow better coding practices. Now in your loop instead of a call to "doorOpen()", I changed it to: if (!noNoise) doorOpenSound(); Which makes it easier to understand what it does. I probably should've renamed the noNoise variable to silentMode to avoid the double-negative of !noNoise. I already spent over an hour on it, and decided that's enough for now. The modified version compiles to 322 bytes. I suspect if I spent another hour optimizing the logic of your state machine loop I could get it down to around 250 bytes. https://gist.github.com/nerdralph/1b99c1b683024e8f305dc06838200208

RalphBacon commented 4 years ago

I should have mentioned that I had to edit the Core>Main so I could use a main( ). I moved the attribute to my own sketch so it was placed in the correct place (.init9). I tried to incorporate your touch routine into my sketch but whilst it works independently (as you saw in my latest video) when part of the Fridge Door Alarm it does nothing (the touch is not detected). I tried it with both MicroCore and PicoCore. Like you, I've spent enough time on it today! I'm well impressed that you have compressed the code to 322 bytes. I wonder if I will recognise my own code now?!? Just for completeness I attach the unmodified version of my Fridge Door Alarm which might well be the same as in my GitHub. sketch.txt

Kaspi314 commented 3 years ago

I just released v0.2-beta. https://github.com/nerdralph/picoCore/releases

Try downloading it and extract it into your Arduino/hardware folder. The only major thing not implemented yet is Serial.

I'm going to try this now on my tiny85 board.

Can you add this to the readme so that other people won't have to look so hard to figure out how to install it?

nerdralph commented 3 years ago

@Kaspi314 I'll consider it. However I don't want to make it so easy that people can install and use picoCore without actually understanding what they are doing.

RalphBacon commented 3 years ago

At the moment I can't test any further versions as all my workshop components are packed up ready for an imminent house move. But I have not lost interest and am following developments here.

I see beta v0.3 now released; I'll be interested to see what you mean by "serial bootloader support using picoboot-lib, and runtime variable delay()." No response required, I shall just keep an eye on this!