[Microbit-Python] Microbit Digest, Vol 13, Issue 8

Damien George damien.p.george at gmail.com
Mon Jun 6 11:08:02 EDT 2016


No, there isn't any list of available module.  We really should make one!

If you want to be able to access arbitrary memory then uctypes is the
way to go (there is also machine.mem8/16/32 accessors for peek/poke
but they are also not enabled on the microbit).

We can enabled these features, but they take flash space and there's
not much left...

There is a way at the moment to access arbitrary memory, using inline assembler:

@micropython.asm_thumb
def peek(r0):
    ldr(r0, [r0, 0])

@micropython.asm_thumb
def poke(r0, r1):
    str(r1, [r0, 0])

The first argument is the memory address.  The second argument to poke
is the value to put.  They are both 32-bit accessor functions and the
address must be 4-byte aligned.




On Mon, Jun 6, 2016 at 3:52 PM, Coryan <coryanws at gmail.com> wrote:
> Hi Damien,
>
> Thanks for that, I didn't know that struct was available to import - though
> unfortunately it's more the ability to access arbitrary memory that I need
> (I don't mind if it's returned as a bytes object, or a list of ints, or
> whatever else.)
>
> Is there a list of all the modules I can import from Micropython?
>
> Thanks for your help,
>
> Best,
> Coryan
>
>
>> ------------------------------
>>
>> Message: 5
>> Date: Mon, 6 Jun 2016 15:41:57 +0100
>> From: Damien George <damien.p.george at gmail.com>
>> To: For Pythonic MicroBit related discussions <microbit at python.org>
>> Subject: Re: [Microbit-Python] Manipulating memory with Micropython
>> Message-ID:
>>
>> <CANw+Mzm6C-tun5YHfLkCowcX+MOzzZFF2=F2CJjyzu3-bWVXPQ at mail.gmail.com>
>> Content-Type: text/plain; charset=UTF-8
>>
>> You can try the (u)struct module:
>>
>>>>> import struct
>>>>> buf = struct.pack('BHI', 1, 2, 3)
>>>>> buf
>>
>> b'\x01\x00\x02\x00\x03\x00\x00\x00'
>>>>>
>>>>> struct.unpack('BHI', buf)
>>
>> (1, 2, 3)
>>
>> Only thing is that it can't access arbitrary memory at a specified
>> location, only bytes/bytearray objects.
>>
>>
>> On Mon, Jun 6, 2016 at 3:32 PM, Coryan <coryanws at gmail.com> wrote:
>>>
>>> Hello folks,
>>>
>>> Micropython seems to have a pretty cool module called "uctypes" which,
>>> amongst other things, allows you to access data from memory and work with
>>> it
>>> in your Python script as a bytes object.
>>>
>>> I'd quite like to do something similar on the Micro:Bit, but it doesn't
>>> seem
>>> like uctypes or any of its contained functions are included in the
>>> Microbit
>>> module. Does anyone know if there are any other fuctions available that
>>> might do something similar?
>>>
>>> Thanks so much for your help,
>>>
>>> Best,
>>> Coryan
>>>
>>> _______________________________________________
>>> Microbit mailing list
>>> Microbit at python.org
>>> https://mail.python.org/mailman/listinfo/microbit
>>
>>
>> _______________________________________________
>> Microbit mailing list
>> Microbit at python.org
>> https://mail.python.org/mailman/listinfo/microbit
>>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit


More information about the Microbit mailing list