Flotilla Python API: Can't get the number module to work

I’m teaching a bunch of kids (9-14years old with little or no experience) robotics with a flotilla kit, and whilst the existing python library works really well it’s not ideally suited to use with kids; it’s kinda complex and requires a lot of code to setup the flotilla before something actually happens. There’s also little documentation available although I know it’s something that’s being worked on - I imagine that in a year or so the python library will be a bit more fully fledged and so better for teaching and that’s fine.

Anyway, TL;DR I am trying to wrap the existing code needed to control the modules into an uber-simple library- which ideally will literally require something like

import easyflotilla
easyflotilla.setup()
easyflotilla.motor(100)
or print("easyflotilla.colour") or whatever.

I’ll try and make it available somewhere online for people in the same boat as me when I’m done.

Anyway, here’s my hastily adapted test code so far:

#!/usr/bin/env python

import sys
import time

import flotilla


print("""
Check colour
""")

COLOR_INFO = "{red},{green},{blue},{clear}"
client = flotilla.Client()

print("Client connected...")

while not client.ready:
    pass

print("Finding colour module...")


#we should scale all values to 1000 I think

col = client.first(flotilla.Colour) #y - the values scale 0 to 25
mat = client.first(flotilla.Matrix)#y
mot = client.first(flotilla.Motor)#y - values are 0 to 63/-63 (f/r)
num = client.first(flotilla.Number)#n
tou = client.first(flotilla.Touch)#y
dia = client.first(flotilla.Dial)#y - the values scale 0-1023
joy = client.first(flotilla.Joystick)#y - the values scale from 0 (right/btm) to 1023 (top/left) - scale -1k to 1k or will this cause errors?
sli = client.first(flotilla.Slider)#y -s scales 0  to 1023
wea = client.first(flotilla.Weather)#y
acc = client.first(flotilla.Motion)#y
#lig = client.first(flotilla.Light)#y


'''
if color is None:
    client.stop()
    sys.exit(1)
'''
i = 0


#mot.set_speed(0)
#num.set_number(0)
'''for i in range(10):
    for j in range(10):
        mat.set_pixel(i,j,0)'''


#MONSTER EXAMPLE LOOP (comment out stuff you didn't connect)
try:
    while True:
        print(COLOR_INFO.format(
            red= col.red,
            green=col.green,
            blue=col.blue,
            clear=col.clear))
        time.sleep(0.5)
        #mat.set_pixel(1, 1, 1).update()
        #mot.set_speed(-63)
        num.set_number(int(1234))
        if tou.one:
            print("True")
        print(dia.position)
        print("x", joy.x, "y", joy.y, "button?", joy.button)
        print("slider: ", sli.position)
        print("temp: ", wea.temperature, "pres: ", wea.pressure)
        print("ax: ", acc.x, "ay: ", acc.y, "az", acc.z)
        #print('light: ', lig.light, "lux ", lig.lux)
        
        

        
        
        
except KeyboardInterrupt:
    print("Stopping Flotilla...")
    client.stop()

All the modules work, except for the number module. I can’t figure out why it’s not working. I’ve tested the module with Rockpool (works fine) but I can’t do numbers or even turn on or off the colon from my code. The code by the way for this is just kinda assumed from the existing flotilla library for the number module.

In essence, the only code that I’ve put in for the number module is this:

num = client.first(flotilla.Number)
num.set_number(int(1234))

Which appears to work for all the other modules - I’ve tried the number on loads of different ports on the dock with loads of different ropes.

What am I doing wrong?

you need to call number’s update method before anything gets printed. That’s what I would assume looking at the code at least.

The Flotilla library definitely needs work, I certainly would concur.

… I would encourage you to contribute to the repo if you are intending to put any amount of efforts towards improving it in the way you envision, as I’m very sure we aren’t dogmatic about what it should look like when it gets a bit of polishing and @gadgetoid will be glad to get feedback on what you (or others delving into it, despite the rough edges) might desire out of the Flotilla API.

I think I tried that already. The update method isn’t needed for any of the other modules - but I’ll try it again when I get a chance.

I’ll definitely try and add my work to the repo when it’s all complete and hopefully child-tested (in about a month or so). I think what I’m really after is just uber-simplification- the quicker the better when you’re teaching kids I have rapidly learned!

Right, version 0.1 has been completed at 11PM the night before it was needed!

It does work quite well though.

I’ve put the code in a separate Github repo for now - https://github.com/archieroques/flotilla-easy - it needs a lot of work and I’m going to improve it over the next few weeks but as of now it offers control of all modules except the rainbow (we only just got one), and a simulation mode if you run the code without a pi or without a flotilla plugged into your pi. Hopefully I will make this look a bit prettier as time goes on but that’s a long-term and slightly unnecessary goal. I also want to scale all the values uniformly, and add a clear_matrix() function to clear it down automatically. There is as yet no support or testing for multiple instances of one module (say two motors) but I want to add this before the next workshop.

I ran a workshop with this yesterday, with 12 kids some of which had never programmed in their lives. Each kid had written code with one input and one output by the end of the session, and they all worked, so the code must be OK!

Thanks for your help (that was the issue with the number module) and for making what genuinely is a really great learning tool for kids.

1 Like