Memory problems

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
Posts: 85
Joined: Tue Nov 07, 2017 11:45 pm

Memory problems

Post by rhubarbdog » Tue Aug 07, 2018 5:43 am

I have bought a small robot for micro:bit but have run into memory allocation issues. I have made a number of cut backs whilst developing this firstly my servo class , found at . It has been cut down to a single instance of ContinuousServo with no inheritance.

I want to add 4 integer parameters to my robot class, i currently have these values hard coded. These numbers are percentages in the range [-100,100]. If this were C and i had memory issues i'd declare these and other percentages as a `signed char` they'd only require a byte of storage.

Is there any way in MicroPython that i can force type to be a short integer or signed byte saving crucial memory allowing for further developments.
Any tips to store are retrieve 6 percentages ?

Posts: 377
Joined: Wed Apr 08, 2015 5:19 am

Re: Memory problems

Post by SpotlightKid » Tue Aug 07, 2018 6:18 am

Use an array.array with typecode 'b':

Code: Select all

import array
a = array.array('b', [1, 2, 3, -1, 2, -3])

Post Reply