Wednesday, 9 April 2025

TinkerCad microbit traffic light simulator (now with video)

Back to playing with TinkerCad in a previous post called explaining-tinkercad-microbit-neural, I used it to produce a simulation of a microbit-based neural network built around microbits. 

If you haven't played with this free tool to TinkerCad https://www.tinkercad.com/dashboard from AutoCad, I highly recommend it as a versatile, simple CAD system (that includes coding for microbits) with a load of support material. If that wasn't enough, it is free and online.

So, to experiment, I have made a simple traffic light simulator (an oldie but a goodie), so I can see what it can do a little more. Essentially, Red, Orange and Green LEDs (with appropriate resistors) are controlled by pins 0,1,and 2 on the microbit.


So here is a circuit with a microbit. The anode (the one with the bent leg)connects to the microbit pins through resistors. The cathode goes to the ground connection.





Here is the code for the microbit turning the LEDs on and off, and when it starts up putting a smiley face onto the microbit.









For those who like circuit diagrams, it can produce a more formal circuit diagram and the parts list (see below)- nice feature.









Have a play with the simulator below it goes a little bit further and changes the smiley face to letters (see the code below)



Possible ideas, change the LEDs to those that change colour, and now the approach can be used to provide a bit of control on the timings of those. Also experimented with replacing the smiley face with letters for LEDs colour (e,g, R for Red) - actually done that in the simulation above with the code below :-)





All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Friday, 28 February 2025

Using Elecfreaks microbit Smart home kit

Using Elecfreaks microbit Smart home kit http://bit.ly/43ooJFo a cool set of comments to build simulated Smart Building activities using a Microbit it works with either V1 or V2.



Start https://makecode.microbit.org/#editor

Go to extensions (see below) and then search for smarthome and add the package to the editor (ie, click on the extension and makecode does the rest)






Attach the microbit to the sensorbit


Making the voice activated light solution - the first activity follow the circuit in the book


To get "led enable" you will need to click in makecode like on LED option and then + to find it. You will also need to set up three variables light, strip and noise.
Here is the code

Only turns on the LED for 10 seconds when the light level is low and noise is above 78dB.


Playtime
Slight adaptation to the code, makes the LED change with sound level
The circuit is the same.


Conclusion
Based on this one activity it is a nice bit of kit. The range of actuators and sensors justifies the cost with things like moisture sensor , servo, water pump, OLED screen, temperature sensor, fan and more. It is worth a look.






All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Sunday, 24 November 2024

Who wants to produce AI produced cartoon strips

Question: How easy is it produce a comic/cartoon using genetative AI?


Let's start with using ChatGPT4o to produce cartoons. The idea was inspired by a tweet by Dr Thomas Lancaster see below




Slightly modifying the prompts it is possible to get it to create the images and combine them in a GIF. I have split the two task into two prompts 

The first prompt applies some principles of prompt engineering
Persona: In this case two the persona of the writer "You are an experienced comic book designer and a witty writer" and who it is for "Computing student in Higher Education in the UK"
Task: Creating a guide that educational and entertaining, but with minimal textual output.
Action: The details a comic with 8 panels of consistent style, create each panel as a separate image; using speech bubbles with a maximum of 5 words.

The first prompt
The language is British English. You are an experienced comic book designer and a witty writer. Create a guide to being a Computing student in Higher Education in the UK using a comic book narrative. This should be educational and entertaining. The comic will have 8 panels and the style consistent between panels, You will generate the graphics for each panel separately; as seperate images. using speech bubbles (a maximum of 5 words). Reduce all other textual output to a minimum. 


The second prompt is all output generating the images and then combining them into a named gif.

generate the images and combined the images into a file called computing_student2.gif



It is fun to do, the text can often get a bit mangled though.




We don't just have to use ChatGPT; Google's Gemini can go someway to also produce a comic or the artwork. There is a differences though (whether it is an advantage or disadvantage depends on what you want); Gemini can not
- Produce images but can find them online;
-Can't combine them into a GIF so that would have to be done outside of this.

So the prompt
The language is British English. You are an experienced comic book designer and a witty writer. Create a guide to being a Computing student in Higher Education in the UK using a comic book narrative. You will use images you find on the web to do this. This should be educational and entertaining. 

The result

A Guide to Computing Student Life

Panel 1

Student: "So, you've chosen to study computing. Brave soul!"

Panel 2

Student: "Endless coding marathons. Your new best friend: caffeine."

Panel 3

Student: "Group projects: where chaos meets collaboration."

Panel 4

Student: "All-nighters are a rite of passage. Bring snacks."

Panel 5

Student: "Nail that presentation and you'll feel like a coding rockstar."

Panel 6

Student: "Remember, breaks are essential. Your sanity depends on it."

Panel 7

Student: "The job market loves computer grads. Your future is bright!"

Panel 8

Student: "You made it! Celebrate your hard work. You earned it!"

Note: I couldn't combine the images into a GIF as I don't have access to image manipulation tools. However, you can easily combine these images into a GIF using online tools or software like Photoshop.

Would you like to focus on a specific aspect of computing student life for the next comic?




So because it is getting image online rather generating them as in the ChatGPT4o approach, the image style may not be as consistent. It does do a good job and  does include the sources of the images; and is quick.


So overall, this was fun to play with; both approaches met the goal though in different ways.


All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Saturday, 24 August 2024

Remote Data Logging with V1 Microbit


In an earlier post https://robotsandphysicalcomputing.blogspot.com/2024/08/microbit-v1-datalogging.html a single microbit was used to log data. The main problem with this is often we want to sense things that are away from the computer ie remotely (though only a short distance away). The previous solution was attached to the computer to work. So one solution (and closer to solutions used in the 'real-world' is to separate the sensing part and receiving and processing into two different devices. So in this case two micro bits; one collecting and sending data, and the other receiving and transferring the data to the computer.

 

How?

So to play with this, we are going to extend our previous solution https://robotsandphysicalcomputing.blogspot.com/2024/08/microbit-v1-datalogging.html to be a remote monitoring system; and the easiest way to get started is with a solution that already exists and adapt it. So we going to use the solution found in https://microbit.org/projects/make-it-code-it/makecode-wireless-data-logger/ as our starting point (I would suggest literally use the makecode provided and then adapt it)

 

Advice: To avoid confusion when programming the microbits; as well as using separate makecode I would suggest programming them separately and only have one microbit at a time plugged in to the computer, to avoid confusion.

 

Microbit 1: Transmitter and sensors

For those that don’t know; microbit can send bits of data over short distances to and from microbits, details on how can be found at https://makecode.microbit.org/reference/radio. For this application we create a 'group' really just give the group a number, and then send our sensor values by radio.

We are going to keep sending the values, light and temperature, but not connect it to the computer directly (after programming) so the microbit in use will need a battery to power it but can be moved away from the computer - it's remote!

 

Here is the code:




 

 

Microbit 2: Reciever

This is the one we keep connected to the computer.

What we need to do is the following

-            Use the same radio group number as the transmitter

-            -Receive the radio signal and based on the name received (in this case x or y) allocated the value sent with the name to a variable.

-            -finally write the values to the screen (just as we did with the single microbit solution) and display them.

Figure 2 Reciever

 

 

Summary

Essentially we have split what we did in the first activity across two microbits connected by a radio link. Running the "Show data" button on the receiver MakeCode window; as before you should get something like this.

figure 3 Data logging remotely

Unless temperature is changing fairly quickly you might not see a great deal of change but hold the transmitter in your hand and you will see some changes. The light level can be made to change also be moving the transmitter so the LED array is pointed at bright screen

 

To save the data as a CSV file and view later in an spreadsheet; as before just use the blue download icon.

 

Some suggestions for improvement

-            When the two microbits are running without the graphs by just looking at the microbit, especially the transmitter, it is not clear that it is doing anything. So could something we added to fix this?

-            Play around with the sampling rate (ie. how often do you send data). So in the transmitter do what we did in the our single microbit solution, replace the forever loop with one that send data every so often.

Have fun.


All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Thursday, 22 August 2024

Microbit V1 datalogging

Often we need applications that allow collection of data over time, for example temperature or light levels through the day. Allowing us potentially analyse the data for trends. The microbit is a fantastic tool, with some of these sensors already in place (e.g. light and temperature) or can be added to with extra sensors from add-on boards (such as Kitronik Air Quality and Environmental Board for micro:bit https://shop.pimoroni.com/products/kitronik-air-quality-and-environmental-board-for-micro-bit?variant=39475687227475 )

 

Datalogging with a V2 microbit is relatively easy all the details are available here: https://microbit.org/get-started/user-guide/data-logging/ to get started.

 

But what about the older V1 can it do it?

 

The answer is yes but it is a little more work and is generally a little more limited but still very worth while. In this post we are going to look at doing this.

 

In Figure 1 starting the process off in MakeCode (https://makecode.microbit.org/#editor) is shown below. Basic mechanism every 1sec

  • -            The light level is write from the microbit to the computer (via the USB) a value at a time – serially
  • -            Same thing will be done for temperature

That is it to start with.

Figure 1

Figure 2 shows where various elements are in menu. To get the Serial ones you will need to open up the Advanced menu and then Serial menu options (see figure 3)

Figure 2

 

Figure 3


Figure 4


Once everything is set up,  under the similar microbit (Figure 4) you will see another button “Show data Simulator” We can play with the microbit simulator to simulate light and temperature levels; click on new data simulation button and graphs starts rolling across the screen – drag the temperature and light levels on the microbit simulator and you see the graphs change – it is logging the simulate data – it works!

Now for the fun bit.

Click on Download we need to pair the computer and microbit. Figures 5 to 8 show the steps.

Figure 5


Figure 6


Figure 7


Figure 8





We can now take values from the real device. A new button should have appeared along with the “Show data Simulator” button; “Show data Device” Click on this button and instead of simulated data we get data from the  microbit (see figure 9)

Figure 9

 

So in figure 9, the top graph is light level the bottom is temperature taken from the room. Play with covering the sensor the LED grid and light levels change.

 

Collecting data is great, but we are taking it one step further logging the data over time and then sharing it To do this click on the blue download button above the graphs to save the logged data as a CSV file. Once it is in CSV format it is yours to play with in other tools such as spreadsheets.

 

 

Activity

-            how can this be more meaningful?

-            How do we do this with so a microbit can see data – some more remote monitoring (see https://microbit.org/projects/make-it-code-it/makecode-wireless-data-logger/ )

-            How could you do this in Python





All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Thursday, 4 April 2024

Top posts on this blog in March 2024

The Top 10 viewed post on this blog in March 2024. Covering areas such as small robots, augmented reality, Scratch programming, robots.






All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

TinkerCad microbit traffic light simulator (now with video)

Back to playing with TinkerCad in a previous post called  explaining-tinkercad-microbit-neural,  I used it to produce a simulation of a micr...