/microbit-radio

A Micropython and MakeCode Blocks compatible radio

Primary LanguagePythonMIT LicenseMIT

Micropython-MakeCode compatible Radio


Class make_radio includes all the functionality of the Micropyhton radio module, while being compatible with MakeCode blocks. When you instansiate the make_radio all the parameters of radio.config are available which make sense. Whilst keeping the radio configured to work between Micropython and MakeCode. The radio can be switched .on() and .off() with those methods. You can send a number (integer or float) with method .send_number(number) . Send a value pair (a string with a number) with method .send_value(value, number). Or just send a string with the .send_string(message) method. Unlike MakeCode blocks with which in a single program you can only accept one of a number, value pair or a string. Micropython provides the convenient .receive_packet() method. The return values are:
  • None - no data was read or the packet was of an unspecified type
  • a string - A message was received
  • a tuple - A value pair was received
  • an int or a float - A number was received

  • if required use the python function type to determine the packet type.

    Some MakeCode Test Programs

    Blocks radio producer
    Blocks radio consumer (receive messages)
    Blocks radio consumer (receive values)
    Blocks radio consumer (receive numbers)

    Note


    For this to work both Micropython make_radio and MakeCode blocks radio must use the same group. You must include the block radio.setGroup()