Version 2 of the BBC micro:bit was released very recently. It has new capabilities, such as a speaker and microphone for audio capture and sound generation but it retains many of the things we came to know and love in V1 of the micro:bit, including Bluetooth. Most importantly, it has way more memory.
Thanks for the Memory
V1 had only 16Kb RAM and the standard runtime code known as the DAL plus the Bluetooth software stack from Nordic Semiconductor consumed 14kb or 15kb depending on configuration. This meant that you were only able to contribute very small amounts of your own code, a serious constraint.
V2 of the micro:bit has a whopping 128Kb RAM which has tremendous implications for what you can get done with the new device. Not only will you be able to write much more substantial code for your micro:bit, but you will be able to use Bluetooth in previously impossible ways. Micro:bit V1 could only act as a Bluetooth GAP peripheral whereas V2 can be a GAP peripheral, GAP central or.... both (see references below). In simple terms this will mean that micro:bits will be able to communicate directly with other micro:bits. And Bluetooth has far better range and reliability than the vanilla "radio" technology.
Compatibility
It's important to note that hex files created prior to coding editors being updated to support micro:bit V2 will continue to work on a V1 micro:bit (obviously) but will not work on a V2 micro:bit. To get your favourite code working on a V2 micro:bit you will need to regenerate the hex file from your source code using a version of coding editor that supports micro:bit V2. Currently, the makecode beta editor supports V2 but the production web site does not (yet).
Significantly, the hex file format has been changed and the new format is known as the universal hex. This format works on both V1 and V2 micro:bit hardware (subject to memory limitations and hardware features used). So, the best course of action is to rebuild your old scripts so that you have hex files which will work with both micro:bit versions. That's what I'll be doing with the Bitty Software open source code examples.
But how can you tell which type a hex file is? It's quite simple. A v1 format hex file is about 700Kb in size but an equivalent universal hex format file will be about 1.8Mb.
Codal
Micro:bit V2 uses new runtime code known as Codal. It serves the same purpose as the DAL on a V1 micro:bit, providing drivers and a framework and APIs which make it easier to create your own applications.
Bluetooth
Micro:bit V1 had a pretty old version of Bluetooth Low Energy (LE), compliant with version 4.1 of the Bluetooth core specification which was released back in 2013. Bluetooth has changed in many ways since then.
Micro:bit V2 has a version Bluetooth LE which is compatible for version 5.1 of the Bluetooth core specification. Version 5.0 added some amazing capabilities to Bluetooth including the ability to communicate over a range of about 1 kilometre using something called the LE Coded PHY. Such capabilities are optional however, so a device with 5.0 or later compatibility does not necessarily have all of the features in that or later releases. From a quick glance at the documentation for the Nordic Semiconductor S113 stack which is used by Codal, it looks like the long range LE Coded PHY capability is not supported. That's a shame.
The collection of Bluetooth services that constitute the device's Bluetooth profile, have been reimplemented in Codal. This is great news because it means applications such as Bitty Data Logger will continue to work unchanged and unaware that the remote device is a V2 or V1 micro:bit.
I did some basic testing and was largely successful. I found and reported a few glitches which I expect will be fixed soon. Here are my test results:
Issue 28: bluetooth all services hex file has an issue (long standing, I imagine). The magnetometer service does not transmit compass bearing data. The sample code probably needs to calibrate the magnetometer at start-up.
OK: accelerometer service
OK: magnetometer service (provided the magnetometer is calibrated first)
Issue 26: button service - Notifications rarely sent on button A long press. Worked once on button B but never subsequently. A single click and release (short press) works and transmits a value of 1 as expected, but holding the button down for 2 seconds or more (long press) does not transmit anything (expected a value of 2).
OK: event service
OK: LED service
OK: Temperature service
OK: UART service
Issue 27: IO Pin service not working - Switching on pin 0 (and perhaps others) does not work. Tested by connecting an LED to pin 0 and then writing 0x000101000200 to the pin data characteristic.
Conclusion
micro@bit V2 looks absolutely tremendous and I'm looking forward to seeing the impact it has!
One of the nice things about Bitty Data Logger is that you can use it without needing access to the internet. You can capture and chart data over Bluetooth from your micro:bit, export the data locally on your smartphone and then view it in a suitable application. This article will run through the basic process.
1. Scan and Connect
As usual, you must first scan to discover your micro:bit and then select it from the list of devices to connect to it.
Scanning for micro:bits. Select to connect.
2. Settings
Next, go into the Settings screen and ensure the right options are selected. The application will do its best to choose defaults which make sense given whatever code you are running on your micro:bit.
Select appropriate settings from the Settings screen
3. Capture some data
Press the Start button, capture some data from your micro:bit and then press Stop when you've captured enough.
Data capture
4. Review results and export
Go into the Results screen. You'll see your data at the top of the list of results files. Select your results file. If this is the first time you have viewed a results file, you will be asked to set an export preference. You can always change this in the Options screen by the way. To use your data offline, one of the easiest options is to select Save Locally.
Save Locally is a good export option for use with no internet access required
You could also use Copy/Paste so that data can be copied to the clipboard and then pasted into another application running on your smartphone. Alternatively, the Share option will allow you to select another application to send the data directly to when you export.
Note that the options offered under Data Export Preferences will vary depending on whether you are running on Android or iOS. The image above is a screen shot from Android. Here's what the same screen looks like on iOS.
Data Export Preferences on iOS
5. Using the Save Locally export option on Android
In the data results viewer screen, select Save Locally.
Save Locally on Android
A message will tell you where your data was saved.
Find the Downloads application or another file system browser application and launch it.
The Download application
Find your file, select it with a long press and then select Open With from the menu.
Select Open With to choose the application with which to view your data
Open with Google Sheets or similar.
Google Sheets works very well with Bitty Data Logger data
Your data will be presented, in this case within Google Sheets. Select a range of data to draw a chart.
Select a range of data for charting
Select the + button and add a suitable chart.
Add a chart
6. Sharing data with Apple Numbers
If you're running on an iOS device, the Apple Numbers spreadsheet application is a good tool for viewing your data. Select Share as the preferred data export option as shown above. View your results file and select Share to export it.
Select Copy To Numbers
Select Copy to Numbers to have your file copied into a new Numbers spreadsheet.
Your data after copy to Numbers
Select a data range.
Select a range of data for charting
Select the + button and add a chart.
Select a suitable chart type
Voila! Your chart will appear
7. Conclusion
Bitty Data Logger works very well without internet access. Good luck with your next project!
Bluetooth devices will play one of 4 possible Bluetooth roles as defined by that masterpiece, the Bluetooth core specification. The four roles are called
Peripheral
Central
Broadcaster
Observer
These terms are part of "GAP", the Generic Access Profile, which is a part of the Bluetooth architecture.
A Peripheral advertises, inviting and (perhaps) accepting connections from Central devices. 'Advertising' means transmitting small amounts of data, quite frequently, which other Bluetooth devices can receive and act upon if they think the advertising device is of interest.
A Central device scans, looking for advertising packets and based on their content, may decide to connect to a device it thinks is suitable.
A Broadcaster is like a peripheral in that it advertises but it does not accept connections. It's sole purpose is to advertise.
An Observer scans and processes advertising packets but never tries to connect to another device.
Examples:
The BBC micro:bit is a Peripheral.
A smartphone is typically a Central but some newer devices can also act as Peripherals with the right application software running.
A Bluetooth beacon (iBeacon, AltBeacon, EddyStone and so on) is a Broadcaster.
A beacon application on a smartphone which alerts you to special offers broadcast by beacons for example, is an Observer.
A Peripheral cannot create connections, only accept them. Therefore a Peripheral cannot connect to another Peripheral. A Peripheral cannot scan for advertising packets from other devices, only transmit them. Therefore two Peripherals cannot interact using advertising data only.
The outcome of this is that one micro:bit cannot talk to another micro:bit *directly* using Bluetooth. You'd need a Central mode device acting as a hub and relaying messages between micro:bits. My Heart Rate Monitor video shows a smartphone acting as a Central hub which is connected to two Peripherals, a BBC micro:bit and a heart rate monitor.
Technically, a device like the BBC micro:bit could have the ability to be either (or both) a Peripheral and a Central but there's just not enough memory available on the micro:bit to squeeze the larger Bluetooth stack that would be required to support both GAP roles, at least not when you are using the official DAL firmware that is. Other SDKs which allow you to program a micro:bit may be lean enough to make this possible.
That's it. An introduction to Bluetooth GAP roles and their relevance to BBC micro:bit. Amaze your friends at your next dinner party ;-)
This post has been reproduced and slightly tweaked from an equivalent article I wrote for another of my blogs a long time ago.
Today marks the release of a new version of Bitty Data Logger for Android and iOS. BittyWeb users, don't worry.... the new release will be with you soon.
So what's new in this release and why were these changes made? Let's take a quick walk through:
1. User Code Capture Mode
The concept of 'capture mode' has been introduced. For the accelerometer, magnetometer and temperature data sources, the choices of capture mode are AUTO and USER CODE. For general data (previously known as 'pin data'), the choice is restricted to USER CODE.
AUTO Capture Mode
This represents the way in which data was acquired from the accelerometer, magnetometer or temperature sensor previously. Your remote device (e.g. a micro:bit) must have the Bluetooth accelerometer, magnetometer or temperature services in its code, typically achieved with a single block in MakeCode and.... well, that's it. You don't really need to do anything else since those services will take care of sampling data from the associated sensor and transmitting it to Bitty Data Logger automatically.
AUTO capture mode is the mode to use unless you have a good reason not to.
USER Code Capture Mode
User Code capture mode is available for all data sources
In the new User Code Capture Mode, your code on the remote device is responsible for acquiring data from wherever it might be, calculating it or deriving it in some other way - the choice is entirely yours. Your code must also transmit it over Bluetooth using the UART service, and in the correct format.
Think of the UART service as allowing you to send and receive messages or byte arrays. It can handle any data, subject to a maximum message length of 20 bytes. A special set of messages have been defined for communication with Bitty Data Logger and you can find details in the new Bitty Software GitHub repository.
Any of the four data types (accelerometer, magnetometer, temperature and 'general data') can be acquired using USER capture mode. General data can only be acquired using USER Code Capture Mode, though.
Motivation and Benefits
So, why was this change made?
USER Code Capture Mode allows you to separate capturing data from transmitting it over Bluetooth. This could mean, for example, that you could write some code for your device which captures data and stores it to a file system as it is being captured. Later, perhaps when a button is pressed or when a Bluetooth connection is established, you'd then read through the stored data and transmit it to Bitty Data Logger. This would be useful in situations where you want to place your device somewhere that it is not practical to have a Bluetooth connection to a smartphone, such as in the great outdoors!
How do you transmit data in user capture mode?
The Bitty Software GitHub repository has lots of code examples. But here's one of them, showing simulated 'general data' being acquired and then transmitted using the UART service.
let connected = 0
bluetooth.onBluetoothConnected(function () {
connected = 1
starttime = input.runningTime()
})
bluetooth.onBluetoothDisconnected(function () {
connected = 0
})
let message_type = 0
let timestamp = 0
let starttime = 0
let value1 = 0
let value2 = 0
let value3 = 0
let value4 = 0
bluetooth.startUartService()
let message = pins.createBuffer(11);
function transmitData() {
timestamp = input.runningTime() - starttime
message.setNumber(NumberFormat.Int8LE, 0, message_type);
message.setNumber(NumberFormat.Int32BE, 1, timestamp);
message.setNumber(NumberFormat.Int16BE, 5, value1);
message.setNumber(NumberFormat.Int16BE, 7, value2);
message.setNumber(NumberFormat.Int16BE, 9, value3);
bluetooth.uartWriteBuffer(message)
}
basic.forever(function () {
if (connected == 1) {
message_type = 1
// random numbers used solely for demonstration purposes. Acquire your data here as required.
value1 = Math.randomRange(0, 1023)
transmitData()
message_type = 2
// random numbers used solely for demonstration purposes. Acquire your data here as required.
value1 = Math.randomRange(0, 1023)
transmitData()
message_type = 3
// random numbers used solely for demonstration purposes. Acquire your data here as required.
value1 = Math.randomRange(0, 1023)
transmitData()
message_type = 4
// random numbers used solely for demonstration purposes. Acquire your data here as required.
value1 = Math.randomRange(0, 1023)
transmitData()
}
basic.pause(1000)
})
It may also be easier to implement the UART on devices which do not automatically have it, like the BBC micro:bit does, than implementing each of the other services.
Note: The Bluetooth Event Service is no longer used for transmitting general data (previously known as 'analog pin data'). You will need to change existing code to use the UART service instead, as shown above.
2. Pin Data is now called General Data
Previous versions supported Analog Pin Data as a data source. The original idea was that you would connect something like a sensor to one of the 3 analog pins numbered 0, 1 or 2 on the edge connector of a micro:bit and that data would be sent as micro:bit 'events' to Bitty Data Logger. It became apparent that people wanted to capture data from other sources, other pins for example. This was technically possible already but meant you might use pin data #0 as a container for data acquired from pin 9, which worked but was potentially confusing. So the is a simple renaming of the concept. 'General Data' items can come from anywhere you like.
3. Up to 4 x General Data Items are now supported
Previously, a maximum of three pin data items could be captured and supported at the same time. The new release allows you to capture and chart up to four general data items. Ideal for use with products like the Sparkfun Weather:bit, perhaps!
Plotting simulated data transmitted from user code
4. Accelerometer data is now captured in milli g force
Previously this data was captured in units of g.
5. X-axis scaling options
Previously, your chart would fill and rescale automatically as new values were acquired. Now you choose to have the chart scroll without rescaling. Have a play with this feature to see its effect.
The Bitty Controller application was designed for maker projects involving the good old BBC micro:bit. But it's always been possible to use it with boards, micro-controllers and computers other than the micro:bit. And with the new release 3.0.0, using it with non-micro:bit devices just got even easier.
The Dual D-Pad UI
Bluetooth
Bitty Controller uses Bluetooth to communicate with remote devices. It sends information about what the user is doing (e.g. the top button in the right hand group was just pressed and then was released) over Bluetooth and in a defined format. The code on the other device has to receive, decode and react to this in whatever way you, the creator of the maker project, want. Maybe you'll want a wheel to start turning or maybe you want to flash an LED. Whatever the response to a user action should be, only you can decide and implement it in your code.
Bluetooth Low Energy (LE), the type of Bluetooth used by the BBC micro:bit and other popular devices like Arduinos and the Raspberry Pi, takes an approach to defining remote interfaces using constructs called Services, Characteristics and Descriptors. The Bitty Software Beginner's Guide to Bluetooth LE describes this quite well, so I won't repeat it here. But the BBC micro:bit has its own set of services (etc), most designed by Martin Woolley (yours truly, in other words!) when he was involved in the micro:bit project a few years ago. A collection of services and the rules for using them is typically known as a Bluetooth 'profile', by the way. The micro:bit Bluetooth profile includes services which Bitty Controller uses for bidirectional communication with a micro:bit.
But what if you want to control a device that uses something other than a micro:bit?
The digital switches UI
Imitating a micro:bit with the micro:bit Bluetooth profile
What's to stop a developer from implementing exactly those micro:bit services on another type of device? And would an application like Bitty Controller be able to tell it was communicating with something which had the same Bluetooth services as a micro:bit but was in fact not a micro:bit?
The answer to the first question is....nothing.
The answer to the second question is.... no. Not if you do it right.
So, your first option for using Bitty Controller with something other than a micro:bit is to implement the required Bluetooth services on your chosen device type.
The analog touchpad controller UI
The Bitty Software GitHub repositories
Bitty Software recently set up some repositories ("repos") on GitHub. Over coming months, we'll publish example code for various types of device, showing how to implement the BBC micro:bit profile on devices which are not micro:bits, so that you can use Bitty Controller and Bitty Data Logger with those devices. See https://github.com/bittysoftware/bitty_controller_device_code for what we have for Bitty Controller so far.
The enhanced touchpad UI with cells for sensor data and a handy button
Introduction the HM-10 style serial profile
Some maker boards do not have Bluetooth, themselves. So if you want Bluetooth, you have to connect an external Bluetooth module, a system on a chip, which allows your board to use Bluetooth. Usually such modules connect to your board's GPIO pins or similar.
There are numerous external Bluetooth modules available, with various designs. The HM-10 is a particularly simple and affordable one. It connects to GPIO pins and uses serial communication to pass data back and forth with the connected board. It's not easy to programme though, so rather than programme it to give it the Bluetooth services you need, instead it comes preprogrammed with one service, containing two characteristics. You use one characteristic to write data from the remote device to the device the HM-10 is connected to and the other allows the HM-10 connected device to transmit data over Bluetooth to the other device. It's like sending and receiving messages.
You can send and receive any type of data you like. You define what the format is in terms of messages and message layouts and your code has to formulate messages and receive and decode them (and then react to them).
The touchpad UI with up to 12 configurable buttons
Bitty Controller and the HM-10 style serial profile
Release 3.0.0 makes it possible for you to choose whether Bitty Controller should use the micro:bit Bluetooth profile or the HM-10 style serial profile.
New - Profile type selector in the Options screen
And this, of course, means it's possible to use Bitty Controller with all sorts of remote devices!
Take Roger Wagner's Hyperduino, for example. This is a very cool piece of kit. The Hyperduino consists of a clever daughter board which makes some potentially complex connectivity and electronics scenarios a breeze to set up. It works with an Arduino Uno and for Bluetooth, uses a connected HM-10.
Roger Wagner's Hyperduino and a connected HM-10 Bluetooth module
HM-10 and Bitty Controller Messages
Bitty Controller has defined a number of message types so that it can convey user interaction information via the HM-10 and can receive data, such as might have been acquired from sensors, from the board the HM-10 is connected to. All messages start with a single byte opcode, whose value defines the type of message. This is then followed by one or more other bytes, depending on the message type. We've published a template Arduino sketch which should make it easy to use Bitty Controller with Arduino-based maker projects. The README file includes details of the messages and their format. See https://github.com/bittysoftware/bitty_controller_device_code/tree/master/arduino/Arduino_with_HM10_serial_template
Happy Making!
That's it! Watch out for updates to the new GitHub repo and good luck using Bitty Controller with you micro:bit and non-micro:bit maker projects.
I sometimes get asked for recommendations on things to read which will help people learn about the basics of Bluetooth, particularly as it relates to the BBC micro:bit. To that end, I've written a "beginner's guide" and released it today. Hope it helps!
Bitty Blue has a new feature called Message Display. It's a very simple idea but one which has a lot of potential. You can now send a text message over Bluetooth to Bitty Blue and it will be displayed. From the user interface, you can change the font size, the background and text colours and you can decide whether the text should be scrolled or not. If scrolling is switched off, sending more text from the micro:bit will replace the current text. If scrolling is enabled, new text will be appended to the current text.
So what might you use this for?
You could use your smartphone or tablet as a graphical console for monitoring your micro:bit code. You could display messages when something significant happens (but checkout Bitty Event Monitoring in BittyWeb for that as well) or display some kind of internal data like the angle a servo has been rotated to. You could even use the feature to help you track down problems in your micro:bit code but sending messages containing the value of an important variable at points in your code!
Sending text involves using the Bluetooth UART service so you must make sure that service has been included in your code, usually from an "on start" block. Then all you need to do from a MakeCode project is use the "bluetooth uart write string" block to send your text. Here's an example.
And here's what you see on your phone when (in this example), button A has been pressed.
Thermal pollution is an environmental issue that we don't hear a lot about. It involves the artificially induced, rapid changing of the ambient temperature of the sea, lakes or rivers and it's a serious problem which can have a devastating affect on fish and other organisms as they succumb to thermal shock.
The most common source of thermal pollution is industry. Power plants and factories which dump heated waste water directly into the sea can cause a rapid increase in water temperature and the death of aquatic life.
I didn't know anything about thermal pollution until a few months ago. In fact, I'd never heard of it and I'd like to share with you how it is that I came to learn about the subject, all thanks to two schoolgirls, Nouf and Mawwadah who live in Saudi Arabia.
Nouf and Mawwadah contacted me by Twitter, asking for some guidance on how to approach a school project involving micro:bit. Their teacher had asked them to think about thermal pollution and how technology might help prevent it and to build a working solution.
The project idea goes like this; imagine the waste water pipes from every factory by the sea were fitted with special devices which could monitor their temperature. If the temperature got too hot or too cold, risking thermal shock, the device could inform a computer system wirelessly, raising the alarm that the factory was breaking the law and causing thermal pollution.
Nouf had seen a YouTube video of one of the Bitty Software smartphone applications, Bitty Blue and knew it had the ability to act as a temperature monitor, with a suitably programmed micro:bit measuring the temperature using its built-in sensor and sending information to the Bitty Blue application. Depending on the information received from the micro:bit, Bitty Blue would display an image and some text indicating whether the micro:bit was telling it that the temperature was OK, too cold or too hot.
Nouf and Mawwadah talked with me using Twitter instant messages and I explained how Bluetooth, one of the most commonly used wireless communication technologies was an important ingredient in the solution. They were quite new to programming and so I did my best to act as a tutor. We talked about the basic logic, the programming concept of an "event", how "events" can be used to trigger Bluetooth communication with the Bitty Blue application and what the transmitted messages would need to contain. With a little guidance and a few more Twitter conversations, Nouf and Mawaddah were able to use MakeCode to create a micro:bit project which did exactly what it needed to. It looped, measuring the temperature every second or so and then sent a Bluetooth message containing a number which meant "OK" (0), "Too Cold" (1) or "Too Hot" (2).
We had covered a lot of information in a short time, and Nouf came up with the idea of sitting down with her sister and explaining the code to her as a way of making sure she understood everything. A great idea and of course in professional programming, walking someone else through your code is something which is commonly done.
So what happened next? Late last year, Nouf made contact again and told me that their school project had been a success. Another friend, Heeba had built a (very impressive) model factory, complete with a pipe which could carry hot water and a pool into which water could flow. With a micro:bit fixed to the pipe, they were able to fully test the idea and demonstrate that their concept worked and worked very well. It sounds like the project was a result of excellent team work, with everyone contributing something important.
Best of all, the team shared a video of her project being demonstrated in class. With permission, I added some captions and published it on YouTube.
If I was a teacher at this school I would award an A+ for this project without hesitation! It's brilliant. I have to say I'd also award Nouf and Mawaddah an A+ for showing such initiative and determination in tracking me down and asking questions in the way that she did. :-)
Here's the video of the team's project.
p.s. BittyWeb, the web-based micro:bit project system from Bitty Software contains an application called Bitty Event Monitor. It's like the Bitty Blue temperature monitor application except that you can use it to monitor *anything* your micro:bit can measure with or without additional components like sensors attached to it. CO2, humidity, atmospheric pressure, vibration... you name it, you can build a fantastic school project with it.
Roger Wagner's MakerBit is an impressive board for micro:bit projects with tons of very well thought through connectivity options, all of which are plug and play, leaving my soldering iron looking sad and neglected on its shelf!
You can buy MakerBit in several forms. As a standalone product, there are two variants. I used the MakerBit R which has additional features for robotics projects compared to the standard MakerBit. You can also get MakerBit in various kits with a wealth of additional components included for you to use in your maker projects.
You can of course invent your own projects, but MakerBit comes with several activity ideas to get you started. They're really well documented and I opted to follow the one for making a "smart car".
Interestingly, there's no chassis provided for the smart car project. Instead, you're encouraged to improvise and reuse a handy cardboard box, perhaps the one your MakerBit came in! I really like this idea. Anything which encourages kids to consider reuse and recycling is good in my book.
I built a "robot bunny" with interchangeable stick on face and programmed the micro:bit so I could control it from either the D-Pad UI or the touchpad UI of Bitty Controller.
A new version of Bitty Controller was released today. A great start to 2019!
The new version offers a 5th user interface variant which is designed to let you drive a machine of some sort *and* control ancillary features of the machine like LEDs and servos. From the options screen you can enable up to 12 buttons and give each a short text label. These buttons will then appear either side of the main touchpad control.
Pressing a button sends a Bluetooth event with ID=9016 and a value equal to the button number in the range 1 - 12 inclusive.
I transformed a GiggleBot into my very own robot dog and used the new UI to take it for a spin. At times... literally. As you'll see, it's very evident from the enthusiastically wagging tail that robodog is a happy dog :-)
Full source code for a MakeCode project is available from the Bitty Software web site as well as a ready made hex file.
Go on! Have a giggle with Bitty Controller and GiggleBot!
Bitty Data Logger users will probably have played with the micro:bit's magnetometer (AKA digital compass) at some point, as will many other micro:bit users, with or without the involvement of Bluetooth.
The magnetometer needs to be calibrated in the environment in which it is to be used, for accurate data to be acquired from it. Originally, simply including the MakeCode "Bluetooth magnetometer service" block was enough to both make the magnetometer data available over Bluetooth *and* initiate the calibration procedure automatically when the micro:bit code started. If you've seen this happen, you'll know that the old procedure starts with the text "DRAW A CIRCLE" scrolling across the micro:bit screen. A single LED then appears and by rotating the microbit with its edge facing upwards, you light each LED on the outer edge of the display. Once a complete "circle" has been drawn, calibration is complete and your micro:bit will continue starting up.
Here's a very simple MakeCode project that could be used with Bitty Data Logger to log magnetometer data:
Things changed in the latest release of the micro:bit firmware (known as the DAL). Now, calibration does not happen automatically. To calibrate your micro:bit's magnetometer you must now explicitly request this in code. There's a block available for just this purpose so you could, for example initiate magnetometer calibration when button A is pressed, like this:
This change may affect Bitty Data Logger users. Magnetometer data will not stream into the micro:bit, even with the right code on the micro:bit until you have calibrated it. Luckily it's possible to initiate calibration from within the Settings screen of Bitty Data Logger:
GiggleBot is a wheeled "bot" from Dexter Industries which you control with a BBC micro:bit.
There are quite a few bots available for micro:bit enthusiasts now, but this one does have a certain je ne sais qoi. Perhaps it's the integral line following and light level sensors or maybe it's the neopixels mounted on its surface. Or maybe it's the expansion possibilities, with multiple points to connect external sensors and dedicated connectors for up to two servos. Or perhaps its the slot through which you can drop a marker pen so that your GiggleBot can draw as you drive. Either way, GiggleBot is full featured, full of potential for some very exciting educational projects and on the whole, tres, tres cool. Oui. Le GiggleBot, c'est bon (with apologies to French speakers everywhere!).
It's also a tough little bot. I drove mine right off the top of a table and it landing with a sickening "crunch" on a hard, wooden floor. Not a problem. GiggleBot shrugged off the impact and got right back to work.
And giggling GiggleBots, Batman! GiggleBot has the best name too :-)
But enough of my thoughts on GiggleBot, already. What's this?
GiggleBot and Bitty Controller work together!
"Really? Oh wow!" I hear you say! Well, yes kind reader, it is indeed true. With the right code on your micro:bit, you can use the GiggleBot's I2C interface to take full control, driving your GiggleBot from your phone using the Bitty Controller app or web browser using BittyWeb. You can also collect sensor data and display it on Bitty Controller's enhanced touchpad controller UI.
C'est magnifique! And it really is :-)
Here's a video demonstration for your viewing pleasure.
You'll find code and information about using Bitty Controller with a GiggleBot right here.
BittyWeb now has a new application called Bitty Event Monitor.
Monitor anything you like using your micro:bit and report significant events to this BittyWeb application and it will indicate whatever is going on with the colour and text that you choose. Suitable for a huge range of classroom and maker projects, you could monitor temperature bands, atmospheric pressure ranges or motion. If you can measure it on a micro:bit using the right code, you can report different states to Bitty Event Monitor for it to indicate visually on your screen.
Watch this video of Bitty Event Monitor working with a micro:bit running some simple temperature monitoring code:
Code for the temperature monitor is available here:
BittyWeb has a new application. It's called Bitty Polyhedra and it's designed to help teach and learn about 3D geometric shapes known as polyhedra. Start by loading our hex file onto your micro:bit or follow the Bitty Software tutorial to make your own. Then, in BittyWeb go into the Bitty Polyhedra application, scan for your micro:bit, select and connect to it.
From there you can explore shapes in the shape library, rotating 3D images of the selected shape on screen using your micro:bit as a controller, tilting or rotating to control the shape on screen.
This week sees some important changes made to Bitty Blue, Bitty Controller and micro:bit blue. The d-pad controller in micro:bit blue has been removed and similarly, the on/off switch control has been removed from Bitty Blue. The on/off controller is now available in Bitty Controller, where logically, it belongs.
Bitty Blue and micro:bit blue are both free of charge but Bitty Controller is a paid for application, albeit with a very low price.
This change has been made to rationalise the functionality in each application and eliminate duplication. Commercial pressures also play a part and it is hoped that users of Bitty Software applications will not object to helping to fund the running of Bitty Software so that applications for micro:bit can continue to be offered.
It's been a year in the making so it is with great excitement that I am able to announce that BittyWeb 1.0 is now available for general use!
BittyWeb puts micro:bit educational applications in the hands of every member of class, exactly where it should be. It's web based so all you need is a suitable web browser and a computer, tablet or smartphone that has Bluetooth 4.0 or later.
There are three applications in version 1.0. Bitty Data Logger, for visualising and analysing data from micro:bit sensors and other things connected to its pins. Bitty Controller let you remote control machines and is ideal for eletronics and robotics projects. Bitty Polyhedra is not quite complete but as you'll see, it provides a fun way to let young students explore the world of 3D geometry using their micro:bit to allow three dimensional viewing of important shapes. More applications are planned too.
To use BittyWeb, your organisation needs an account and to subscribe to use the system for a given period of time, with a selected maximum number of concurrent users. Typically this would be the size of one or two classes.
By the way, the orientation video for V1.0 should whet your appetite!
And here's the applications promo video!
Sadly, despite this being a genius idea, BittyWeb was not as popular as expected and is no longer available.It was fun while it lasted though!
Bitty Software will soon be launching a new system which will make it possible for educators to use applications like Bitty Data Logger in a completely new way and involve the entire class.
The current Bitty Software mobile applications for the BBC micro:bit have proved popular with teachers and STEM ambassadors, allowing invisible physical phenomena to be visualised and analysed, robots to be programmed and remote controlled and coding exercises to be undertaken. But the nature of mobile applications and the policy many schools have on the use of smartphones in class has meant that the applications were only really available to the adults in the room, typically teachers. That's all set to change with BittyWeb.
BittyWeb makes the Bitty Software applications available on PCs running Windows 10 or Linux, and on Macs, Chromebooks and Android devices, in all cases from within a web browser. Yes, all you need is the Google Chrome web browser running on a PC, laptop, tablet or smartphone which has support for Bluetooth 4.0 or later and you're all set to run some of the most immersive and inclusive science, technology and coding classes ever!
To use BittyWeb, organisations will need to register for an account and subscribe to use the system for a certain duration (e.g. 12 weeks) and with support for a given maximum number of concurrent users (e.g. 30 for a whole class). Registering will result in an organisational account being created and a user account for the member of staff who will act as the system administrator for their organisation. That user can then log in and create as many standard user accounts as they are likely to need, typically one for each member of class. Standard user accounts are completely anonymous, by the way.
Version 1.0 of BittyWeb will include the Bitty Data Logger and Bitty Controller applications. Further BittyWeb applications are planned though and we're always open to ideas.
BittyWeb is currently in beta testing and if you'd like access (free of charge of course), please email bittysoftwareuk AT gmail DOT com to discuss.
The code provided at the end of this post will no longer work with Bitty Data Logger. As of version 4.0, micro:bit events are no longer used to transmit arbitrary data values over Bluetooth. Therefore the transmitSensorData function in the code below needs to be changed to use the new approach, with the Bluetooth UART service. See http://bittysoftware.blogspot.com/2019/06/bitty-data-logger-40.html for details and https://github.com/bittysoftware/bitty_data_logger_device_code for Bitty Data Logger code examples.
But good news! Full source code which uses the new approach is available in the Bitty Software GitHub repository, along with a ready-made hex file:
I was recently contacted by a professional educator, based in Alberta, Canada called Jennifer Ferguson. Jennifer (@FergeeksonGirl on Twitter) works for a charitable, education and outreach organization called Let’s Talk Science (@LetsTalkScience) and has been using Bitty Data Logger.
The reason Jennifer made contact was to talk about her current project, Living Space, an education initiative developed with the Canadian Space Agency and to ask for some assistance.
Living Space is concerned with monitoring key environmental conditions, including carbon dioxide (C02) levels. Jennifer wanted to be able to connect a Carbon Dioxide sensor to a micro:bit and to communicate its readings to Bitty Data Logger over Bluetooth so that the data could be visualised, logged and shared.
C02 Monitoring
C02 monitoring is widely used in all sorts of applications, many of them really important, some of them surprising. Examples include heating, ventilation and air conditioning (HVAC) systems, large scale city environmental monitoring, and aspects of food production, including monitoring of plant cultivation environments and improved food storage. It’s used in laboratory incubators for monitoring cell cultures and in healthcare for things like breath analysis applications where the sensor has to deliver results very rapidly, at around 20 measurements per second. Breath analysis data allows for monitoring conditions such as asthma. And of course, a C02 sensor being a sensor, it’s something you’d expect to find in larger scale connected systems which we might file under the umbrella term “Internet of Things (IoT)”.
Jennifer was working with an impressive sensor, the CozIR®-A made by Scottish company GSS (Gas Sensing Solutions). Some models, such as this one can take temperature and humidity readings as well as C02 measurements.
Let’s start by getting to know the CozIR®-A sensor.
Connecting a micro:bit to the CozIR Sensor
The CozIR®-A sensor has a number of pins on its underside. The important ones are GND, 3.3V power and serial receive (RX) and transmit (TX) pins. Yes, the interface is a UART interface, which allows serial communication, one bit at a time using two of the pins, one for transmitting bits and one for receiving. To connect the CozIR®-A to a micro:bit, you make connections like this:
CozIR®-A
Micro:bit
GND
GND
3V3
3V
TX
RX
RX
TX
Note how TX on the CozIR®-A is connected to RX on the micro:bit and RX to TX. This makes sense if you think about it. Data transmitted from the sensor has to be received by the micro:bit. Data transmitted by the micro:bit has to be received by the sensor.
Here’s what a micro:bit connected to a GSS CozIR®-A sensor looks like:
As you can see from the photos, I powered my micro:bit and sensor from a couple of AAA batteries. Jennifer tells me that readings start to get inaccurate when the battery gets low though, so you may prefer to power from a USB cable or other power supply.
Communicating with the CozIR®-A Sensor
The GSS CozIR®-A sensor uses a simple protocol for sending and receiving data and commands over the UART connection with a microcontroller like our micro:bit. All commands and data consist of ASCII characters only and they’re all, always terminated with carriage return, line feed characters i.e. \r\n or ASCII characters 0x0D and 0x0A.
The software guide that comes with the GSS CozIR®-A sensor is very good, and it doesn’t take long to understand the protocol and pick out those commands and responses that are required for your purposes.
There are three operating modes defined. Mode 0, Command Mode stops the sensor from making measurements. It will respond to commands when it receives them but otherwise is more or less dormant. Mode 1, Streaming Mode has the sensor making and reporting measurements every 500ms by default. Mode 2, Polling Mode makes measurements in the background but does not report them unless it receives an appropriate command from the connected micro:controller.
To request a particular mode #, the command K #\r\n must be sent. So for polling mode, the command is K 2\r\n. Note the space character between “K” and “2”.
For the best, most accurate readings, the sensor needs to be calibrated. The protocol supports calibrating the sensor in a number of ways, including in a known gas concentration, which is the recommended approach or, for those of us without a supply of a suitable reference gas, in fresh air.
Requesting fresh air calibration is achieved by sending the command G\r\n to the sensor.
Micro:bit and the CozIR®-A Sensor
Jennifer had already put together a MakeCode application which could acquire sensor readings from the CozIR®-A and display them on the micro:bit’s LED display. Her application made use of a handy package of custom blocks written by Simon Monk of Monk Makes that took care of the nitty gritty details of talking to the sensor, making her application very easy to read. Here’s the original code which she sent to me:
The application starts by configuring the micro:bit serial communications system to use pins 0 and 1 from the edge connector instead of using the USB connector for serial data. It then sits in an infinite loop, calling one of three custom block functions to obtain a C02, temperature or humidity reading, depending on the value of a variable called mode. The mode variable can be changed by pressing button A so that you can switch from C02 to temperature to humidity readings at the click of a button. Values returned by the custom block are simply displayed on the micro:bit LED grid.
The CozIR®-A Custom Blocks and Serial Communications
The CozIR®-A custom blocks which the Let Talk Science application uses, works like this:
There are a number of functions which the application using the block will call, such as the function C02(). Functions like this one send a command to the sensor (in this case Z \r\n) by writing to the serial interface, wait for 200ms and then return the value of a variable which should now contain the latest measurement of the requested type.
export function Co2(): number {
serial.writeString("Z\r\n")
basic.pause(200)
return co2
}
How the variable gets assigned the latest measurement, is explained by looking at the code behind another part of the CozIR custom blocks. Responses to all commands are received from within an event handler, serial.onDataReceived which is called whenever there’s data waiting to be read from the serial port as will be the case when a command has been processed. The response data gets read into a string variable, examined to see what type of response it is and then values extracted and assigned to the appropriate variable. For example, C02 readings always start with a Z then a space and then the value in parts per million (ppm). So this code checks for a response that starts with “Z” and then extracts the associated value:
response = serial.readUntil(serial.delimiters(Delimiters.NewLine))
value_str = response.substr(3, 5)
let value = parseInt(value_str)
// basic.showString(response.charAt(1))
if (response.charAt(1) == 'Z') {
let co2_uncompensated = value
co2 = co2_uncompensated + (altitude * 556) / 10000
}
As you can see above, it’s the variable c02 that gets returned by the Co2() function.
The Micro:bit Event System
The BBC micro:bit lets software components talk to each other using event objects. An event is just data which indicates that something in particular has happened and has an associated value or sub-type. Software components can both generate events and indicate that they’re interested in being notified about particular types of event happening elsewhere in the system, when they occur. For example, I might write some code that wants to know when either of the micro:bit’s buttons is pressed. The software component in the micro:bit firmware that is responsible for handling the buttons, known as a driver, generates events whenever buttons get pressed. All my code has to do to receive these events is to register its interest in this type of event using a micro:bit function, and specify what I want to happen when such an event takes place. In the MakeCode programming system, we’re given ready-made blocks for this purpose such as the onButtonPressed block.
Including the onButtonPressed block in my code, simply means “please tell me if a button gets pressed and execute this code when this happens”.
Events are said to travel along a message bus which you can think of as being like a pipe that events flow along, with some software components injecting event messages into the pipe and others syphoning off copies and processing them.
Technically, events are 32-bit numbers with the first 16 acting as an event identifier (ID) which tells us what type of event it represents and the second 16 acting as a sub-type or an associated value which can be as large as 65535.
Communicating with Bitty Data Logger
Bitty Data Logger uses the micro:bit event system. One of the nice things about the event system is that software components that generate or process events do not have to be inside the micro:bit! They can be connected to the micro:bit over Bluetooth using something called the Event Service. All MakeCode applications which use the Bluetooth package, automatically have the event service built into them, meaning that events can be used for bidirectional communication between the micro:bit and the other device, connected over Bluetooth.
Various event types are used by Bitty Data Logger. These are the ones which were useful in communicating CozIR®-A sensor data:
Event ID
9020
9030
Event Name
Pin Selection
Data
Direction of Communication
bitty data logger to micro:bit
micro:bit to bitty data logger
Purpose
Let’s bitty data logger tell the micro:bit which pins on its edge connector to read data from before transmitting it over Bluetooth.
Each 9030 event has a value which combines a pin number with a value. This is how up to three different types/sources of data from an external device, connected to the micro:bit, can be communicated to bitty data logger.
Data Format
Bits 0, 1 and 2 are used to select pins 0, 1 and 2 for sampling.
For example:
00000010 means pin 1 should be read.
00000111 means pins 0, 1 and 2 should all be sampled.
Bits 0-9 contain value. Bits 15-14 contain a pin no. So a single event value, indicates both the pin that the data comes from and the data sampled from that pin.
In MakeCode, to be notified whenever the 9020 Pin Selection event is sent over Bluetooth from Bitty Data Logger, and to set some flags indicating which of pins 0, 1 and 2 have been selected in the app, this is all we need to do:
To formulate a 9030 data event and send it to the smartphone application over Bluetooth, I usually place the code in a MakeCode function block which I can call from elsewhere, like this:
It’s that easy!
Changing the Let’s Talk Science code to work with Bitty Data Logger
To adapt Jennifer’s code to work with Bitty Data Logger, I decided to cheat a little. I decided to pretend that C02 readings were associated with pin 0, temperature readings with pin 1 and humidity readings with pin 2. Of course, all of these readings are being returned over the micro:bit’s pin 1 which is receiving serial data from the sensor’s TX pin but let’s not quibble. Pretending that the three sensor data types come from different pins, allows us to transmit and classify the three types of data separately so that Bitty Data Logger can capture and chart the data in the usual way.
Reading data from the sensor is performed in a Forever block and only happens if we’ve accepted a Bluetooth connection, indicated by a variable which gets set when a connection is established or lost, in these event handlers from the MakeCode Bluetooth package:
We then request one or more of the three sensor data types, depending on the pins that were set in the Pin Selection event.
Demonstration
Conclusion
The GSS Carbon Dioxide sensor is great for all sorts of science projects and has great relevance to a range of real world issues. As always, Bitty Data Logger allows phenomena to be visualised and analysed, which is a big help in furthering a deeper understanding.
Give it a try! Bitty Data Logger is in the Apple App Store and Google Play.
This code will no longer work with Bitty Data Logger without some changes being made. As of version 4.0, micro:bit events are no longer used to transmit arbitrary data values over Bluetooth. Therefore the transmitSensorData function in the code below needs to be changed to use the new approach, with the Bluetooth UART service. See http://bittysoftware.blogspot.com/2019/06/bitty-data-logger-40.html for details.
But good news! Full source code which uses the new approach is available in the Bitty Software GitHub repository, along with a ready-made hex file:
“We design and manufacture the fastest response, lowest power, and most robust CO2 sensors around. It’s our core solid-state technology that really sets us apart. We make special mid infrared LEDs in-house, and use this solid-state technology at the core of our sensors to help you achieve ambitious power, speed and endurance goals. That means, no warm up time; instant on/off; very low energy (as low as 3mW); no moving parts; and a long lifetime – over 15 years in some applications. As for applications, our sensors have just about done it all – land, sea and space! They’ve been blasted into space, submerged beneath the seas - and most things in between! As engineers and scientists, we’ve amassed years of experience in solid-state CO2 sensor development. We did it first, and that’s all we do, so we know CO2 sensors inside out. That means there’s every chance we’ve already delivered a solution for your application. And if you’re looking to do something a bit special, we can work with you to adapt an existing product, or develop a brand new solution for your project. Just send us your brief and let’s get started!