12/11/2023 0 Comments Wiimotewhiteboard![]() ![]() Here’s an example script of how to use the Wiimote to drive our robot: wiimote.Last week I wrote a blog post about how I was now convinced that the SmartBoard was probably the best interactive whiteboard option for most music education classrooms. That opinion has not changed, but I recently came across a very good blog that devotes itself to the Wiimote Whiteboard system. For those of you that are not familiar with the idea you can make a fully functional yet cheap interactive whiteboard (IWB) for less than one hundred dollars by using a Wii video game remote, a bluetooth USB dongle, and an infrared pen. What you now do is up to you! For information on projects other people have done look at WiiBrew. Wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_ACC #set Wiimote to report button presses and accelerometer state So to make your script a bit more robust, here’s a better way to connect to the Wiimote: it will try a few times, tell you how to connect and quit if a connection isn’t made. It appears that during normal movement the value centres at about 125 with 25 either way (going much higher if you flick it sharply or provide another strong acceleration rather than just gravity). Let’s have it regularly print the state so we can see how it changes as the Wiimote is moved. Now shows us we have an extra field called acc which is a 3-tuple. ![]() ![]() Let’s just have a look at the data we get from it: wm.state This is also very easy to access, first we can make the Wiimote report both button presses and accelerometer state with: wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_ACC Now that we understand the basics of how to use the Wiimote we’ll have a look at its key feature, the accelerometer. Or if you’re using ipython hit tab after typing cwiid. If you want to see what other buttons there are to read, try: dir(cwiid) For instance if you want to see if the button ‘1’ is being pressed: if (wm.state & cwiid.BTN_1): To make it more useful we can check for specific buttons being pressed. If you’re interested only in the button presses try instead: wm.state Try holding down a few buttons and running the program again to see how it changes. To then get all the information the Wiimote is reporting type: wm.state ![]() First let’s have it just report button presses. Now if we want to read values from the Wiimote we must turn on the reporting mode. Now have it rumble for every multiple of 3: for i in range(16): Let’s start by having it count in binary on the LEDs. Now that we have a Wiimote connected let’s try and do something with it. This is however liable to fail a few times and not estabalish a connection but raise a RuntimeError, we will handle this when writing a fuller script. To be able to use the Wiimote we have to import the necessary library so: import cwiidĬonnecting a Wiimote and saving it as wm to use later is now as simple as simultaneously pressing 1 + 2 on your Wiimote to make it discoverable then running: wm = cwiid.Wiimote() Log into your Pi and start a Python console (or ipython if you want tab completion and other extra features). It is recommended to use one of our SD cards or images, if you are not then you will need: python-cwiid and to set your Bluetooth in discoverable mode with sudo hciconfig hci0 piscan. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |