radio in micro:bit

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
PandaTheOne
Posts: 5
Joined: Wed Jun 21, 2017 6:23 pm

radio in micro:bit

Post by PandaTheOne » Wed Jun 21, 2017 6:42 pm

hey guys!

I'm new here and I'm french, so as you all know I'm thaaaaat bad in english. So please do not laugh at me and let me know if I do mistake, I will try to improve ;)

So, like in english I'm really bad in "micro:bit", indeed I'm a beginner. I try to use the radio! so like you can imagine, I started with the code given by the micro:bit website. that is :

[spoiler]
# A micro:bit Firefly.
# By Nicholas H.Tollervey. Released to the public domain.
import radio
import random
from microbit import display, Image, button_a, sleep

# Create the "flash" animation frames. Can you work out how it's done?
flash = [Image().invert()*(i/9) for i in range(9, -1, -1)]

# The radio won't work unless it's switched on.
radio.on()

# Event loop.
while True:
# Button A sends a "flash" message.
if button_a.was_pressed():
radio.send('flash') # a-ha
# Read any incoming messages.
incoming = radio.receive()
if incoming == 'flash':
# If there's an incoming "flash" message display
# the firefly flash animation after a random short
# pause.
sleep(random.randint(50, 350))
display.show(flash, delay=100, wait=False)
# Randomly re-broadcast the flash message after a
# slight delay.
if random.randint(0, 9) == 0:
sleep(500)
radio.send('flash') # a-ha
[spoiler]

So It works haha. But then I thought to myself... I'm lazy so I want to do that without pressing the button A. So I just delete the line :
if button_a.was_pressed()
then I check the code and "Mu" (the software) tell me that I have an error on the line :
incoming = radio.receive()
The error is : Identationerror : unindent does not match any outer indentation level

In fact, I don't really understand the message. So I ask myself If I must to do an action (like press a button) to send and receive things by radio or if their is a way to get around the problem.

Thank's for your answer!

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: radio in micro:bit

Post by deshipu » Wed Jun 21, 2017 8:42 pm

One of the distinguishing features of the Python programming language is that it doesn't use parens like ( and ) or braces like { and } or keywords like BEGIN and END to denote blocks of code, like other programming languages do, but instead it relies on indentation -- that is, the amount of white space at the beginning of the line. But that means, that for the program to run properly, it has to be properly indented -- you can't just remove a line that introduced indentation (like the "if" statement that you removed) and leave the following lines indented, because that will make Python very confused about what you are trying to do.

I think it's best if you start by doing the official Python tutorial at https://docs.python.org/3/tutorial/index.html before proceeding with even more questions like this. This way you can learn a lot about the language itself without having to ask about everything.

PandaTheOne
Posts: 5
Joined: Wed Jun 21, 2017 6:23 pm

Re: radio in micro:bit

Post by PandaTheOne » Thu Jun 22, 2017 8:08 pm

thank's for your answer! I already send a message but it doesn't appear... I don't really know why :/

MODERATOR NOTE: The reason it didn't show up right away is because the first few messages from new users require moderator approval. I disapproved your first message (since it was essentially included in this message) and approved this message.

So I will try to re-edit it. It looked something like that :

Thank's for your answer! you're right I think I have to learn first and do then... I feel "noob" to ask a basic question like that. it's like all the other computer language... First do the "hello world" and then learn to code haha!


So, now I have another question. I don't want you to do a code for me but I want to know if something is possible with the micro:bit because I can't find anything about this subject.

I want to use the radio and the bluetooth at the same time. Let me explain :
I want to use a smartphone to send information like "I'm a man" or "I'm a woman" (I know it will be a binary code of course) to one micro:bit.
Then I want to use the binary code to send it by radio to an other micro:bit. if the code receive by radio is "I'm a man" then active the led 1x1 or if the code is "I'm a woman" active the led 1x2 for exemple.
It could be a strange question I guess. But I try to learn about the bluetooth subject in micro:bit and I didn't find anything about that. In the micro:bit tutorial, bluetooth is not explain (http://microbit-micropython.readthedocs ... t/ble.html) and in the other tutorial I found, the user just play with one smartphone and one micro:bit.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: radio in micro:bit

Post by deshipu » Sat Jun 24, 2017 10:54 am

You can't use the bluetooth on the micro:bit with MicroPython -- there isn't enough memory for that.

PandaTheOne
Posts: 5
Joined: Wed Jun 21, 2017 6:23 pm

Re: radio in micro:bit

Post by PandaTheOne » Sun Jun 25, 2017 6:02 pm

Seriously? so bad :/ You know if their is another way to use the bluetooth? Maybe using other language like C or C++?

thanks a lot!

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: radio in micro:bit

Post by deshipu » Sun Jun 25, 2017 11:14 pm

Yes, you can do that in C/C++, but I have no idea how. You should probably look for it on some other forums about those languages.

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: radio in micro:bit

Post by rhubarbdog » Fri Nov 10, 2017 1:34 pm

Using google.co.uk search for 'lancaster university microbit' i found c++ resources there. I haven't tried any of it as i don't know c++ and have been unable to get any flashing software for linux

Post Reply