Monday, 13 July 2020

Dancing Kitronik's Game Zap - reacts to music

You will glad to hear this is only a short post.  

In an earlier post, Build a Disco Cube:bit that reacts to music; the vibrations of music, makes the cube sitting on a speaker with the volume pushed to 11 (just to test it of course) react to the music. The accelerometers values in the micro:bit, in the three axis, are feedback to change the neopixels colour. Simple but good fun.




With some very minor (and I do mean minor) changes it works on the Kitronik's Game Zap - eight pixels are altered at a time instead of five but apart from that nothing more. The code in python is shown below:

from microbit import *
import neopixel, random

np = neopixel.NeoPixel(pin0, 64)

while True:
    for pxl in range (3,64, 8):
        rd=int(abs(accelerometer.get_x())/20)
        gr=int(abs(accelerometer.get_y())/20)
        bl=int(abs(accelerometer.get_z())/20)
        np[pxl] = (rd, gr, 0)
        np[pxl+1] = (rd, gr, 0)
        np[pxl-1] = (rd, gr, 0)
        np[pxl+2] = (rd, gr, 0)
        np[pxl+3] = (0, gr, rd)
        np[pxl-2] = (0, gr, rd)
        np[pxl-3] = (rd, 0, 0)
        np[pxl+4] = (0, gr,0)

        np.show()


I was impressed with a few tweaks it worked! Please feel to share and copy, if this useful to you please share in the comments.




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

Build your own Neuron in a Spreadsheet.

Purpose: 
To start to understand the basic idea behind how a Neural Network works by building the most basic unit a simple neuron using a spreadsheet.



Objectives:
- To see we can start building machine learning tools in commonly used software applications such as a spreadsheet without a lot of programming (though programming is good fun);
- To see if we change a few values and it changes what the neuron does.



What might be helpful to know before we start?

Don't worry the video will mention these and show you them in action.
  • In the press we see a lot of talk about Artificial Intelligence and Machine Learning and one of these often mention is Deep Learning which is a form of something called a Neural Network. One way to think of a Neural Network is in our brains we lots of processing units called neurones, which are connected together to form a massive network of neurones, which is a neural network. What computer scientists have done is taken the idea and used it create an artificial version so we have a tool that learns.
  • The simplest unit in these networks is the neuron, and we are going to build a simple artificial neuron together. It works by doing two things
    • taking the inputs and multipling them with a value, then adding these multipled inputs to get a single number;
    • we take this single number and use it to decided what the neurone's output is.
  • We can do a lot with a neuron, including building logical operations. In this activity, we are going to look at two basic logic operations the AND (when all the inputs are TRUE (in our case today 1), the output of the neuron is TRUE), the other is OR (when one of the inputs are TRUE, the output is TRUE).
  • Spreadsheets cells have some cool features
    • if instead of putting A2 into a formula in a cell, we put $A$2; if we then copied that cell's content and pasted it another cell the value stored in A2 will always be used, otherwise pasting changes the cell that is used.
    • next is IF, we can build a test into our system =IF( whatever the test is, what happens if the test is TRUE, what happens if the test is not true) .


Task 1: Which Spreadsheet to use and setting up.

Google sheets, Excel can all be used; the process is the same. 

Please watch this video first which will take you through the activity it includes pauses to allow you stop the video to type in the things needed. So watch the whole video first; repeat the video if you need help, stopping the video when you need to. 





Copy the spreadsheet above.

At the end of this task we should have
  • The spreadsheet started;
  • All the columns labelled
  • The inputs set-up
  • Set up some initial values called weights.

Task 2 Adding the rules

In Cell H2 enter the following =$E$2*A2+$F$2*B2+$D$2. What is happening is weight 1 is multiped with input 1, weight 2 with input 2 and these are then added together with the bias. This is the weighted sum

The dollar signs set the formula so that it always uses those values such as E2. Now if we copy this cell and paste it into the three  cells H3,H4 and H4 the formula is copied and its output changes based on the inputs and the weights.

Final stage, in J2 add the following =IF(H2>=0,1,0) . What this says is if the weighted sum is greater or equal to 0 then the output of the neuron is 1 (TRUE) otherwise 0 (FALSE). We are done we have our neuron.
 
At the end of this task we should have
  • The inputs and weights multiplied together;
  • Added the multiplied weighted inputs together to create a single number;
  • Created the rules that say the output is based the single number;
  • See we have an OR gate.


Task 3
At the end of the task we should have seen what can happen when changes the weights - in this case OR becomes AND. To this change the bias value to -2.


Have a play with the weights. Do they always have to be whole numbers? What other values of weights work to produce an AND. You only need to alter bias, weight 1 and weight 2.




Where now? Activities to do later if you want.

If you want to take this further these videos might help



Follow on Activity 1: Training a Single Neuron in a spreadsheet




Follow on Activity 2:  Combining three neurone to make a Neural Network in a Spreadsheet




Follow on Activity 3: Can we build a Simple Neural Network using BBC Microbits? 



Follow on Activity 4: Why do we need to learn about Machine Learning






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

Tuesday, 30 June 2020

10 most read posts (June 2020) on Robots and Physical Computing Blog

Popular Posts



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, 26 June 2020

Easy, Free and no markers Augmented Reality - location based AR

For a few years, I have been a fan of Aframe and AR.js - these are fantastic tools for creating web-based Virtual and Augmented Reality. 

Now AR.js has just got easier - no coding need with the Beta version of AR.js Studio  including using markers (see this previous post for more details) and the focus of this post, geo-located or markerless AR.

It so easy I am going to show two examples. First going to the start screen of AR.js Studio https://ar-js-org.github.io/studio, select location based project type.





You will then be asked for the longitude and latitude on where you want your AR to be located, up to 10 locations can be used - I have only used one to trial it. If you don't know these co-ordinates they have included a link to a site https://www.latlong.net/ (see below) that will give you these and you can then transfer them into AR.js Studio that is the geo location bit done. Now for the thing at the location.



So for the first experiment, I going to use a free 3D model from https://sketchfab.com/3d-models/duck-6e039c6c606c4c26a1359514352629fd produced by likangning93 and released under a creative commons licence on Sketchfab. It is as simple as clicking upload file and browsing. The last stage is publishing it on GitHub and you getting a URL or downloading the files and which you can later add to a server - both really just a click option. 

So the Duck is shown below




So as a follow up and as I think Jupiter is such as a beautiful planet, I used a model by Miekle Roth on Sketchfab https://sketchfab.com/3d-models/jupiter-c5275eb96af245e4a8453837ac728a62 as a second geolocated object. So now I have Jupiter whenever I want - no I am not that power-mad.




Some interesting things I noticed it is relatively easy to do it, and I think the resources downloaded through AR.js Studio could be a great start on a more complex project. Initially, I didn't have location turned on my phone (obvious I know) but I could still see the object when I looked down - so that is great feature to have when you are trying out markerless AR to see what it could look like. 


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, 19 June 2020

Easy, Free and Quick Augmented Reality (AR) - AR.js Studio - Marker based

For a few years, I have been a fan of Aframe and AR.js - these are fantastic tools for creating web-based Virtual and Augmented Reality. 

Now AR.js has just got easier - no coding need with the Beta version of AR.js Studio https://ar-js-org.github.io/studio/


The start screen above gives you the option of location-based or Marker-based projects, I am selecting marker-based and then pressed Start building.

I am going to use the premade marker but you can upload your own )there is a guide to what makes a good marker). The premade marker you can download from the site using the download marker link underneath the marker. Apart from that, you don't have to do anything else to select the marker.

Now you choose whether you want 3D object, image or video. So for this experiment, I going to use a free 3D model from https://sketchfab.com/3d-models/duck-6e039c6c606c4c26a1359514352629fd produced by likangning93 and released under a creative commons licence on Sketchfab. It is as simple as clicking upload file and browsing.



Last stage is exporting the project. Two options 
- Published to Github 
- Download package

My advice is, if you don't have your own web-server, get yourself a Github account and choose that option, and you just log-in to your account. You will need to give the project a name and then push Publish. Depending on your internet connection it can take a few seconds to a minute or so, but it is worth the wait.

So now you get back a URL https://scottturneruon.github.io/Testobjectexs5y2/ . Now just show the marker.




So to test I am typing this URL in a Safari browser (Chrome can play up) on my phone and allow access to my camera (see below or try it for yourself which is more fun).




This Beta version is very good, no coding needed by the user and easy steps to an AR.  At the time of writing the only slight issue was you need to ensure that the file extensions were not capitalised but other than it is a great tool for produce a single AR example. I need to try the location-based version next.




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

Monday, 1 June 2020

10 most viewed post on Robots and Physical Computing: May 2020

Popular Posts


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, 2 May 2020

Programming Robots Virtually 3: LEGO EV3


In this series of posts, I am going to look at experimenting with a few tools that allow robots to be simulated, programmed, these are ideally web-based, free and simple to use. In this post,the focus is on one that has been around for a while Makecode for the LEGO Mindstorms EV3 robotics kit available at https://makecode.mindstorms.com/#editor another example of the flexible MakeCode format. A very useful guide to using this coding tool is available at https://makecode.com/blog/lego/05-15-2018




This time it does not give you a built robot but a programmable simulation of the Brick, all the sensors and motors; which it automatically connects together depending on the code (see above). I like this idea it means it is flexible, as well as encouraging thinking about the design and operations of the programs before trying it out physically.



So to experiment with it.  I played with a number of elements:


When touch sensor is pressed (looks like a box with a cross on it) drive one of the motors forward, when that sensor is released the motor reverses.  Following this I added the ultrasonic sensor (the one that looks like two eyes); when an object is near (controlled in the simulator by moving the slider upwards), the motors B and C rotate 5 times. The code is relatively easy and can be seen below.



Now to play with the brick itself. The first operation, is when it starts add a 'mood' set of wide-open eyes in this case, on the Bricks screen, when the enter button [the central button on the brick], show a happy face on the screen, wait and add a purring sound and write Be Happy on screen. Lastly when Red (a set of pressable colours appears near the sensor) is detected using the colour sensor put an expression on screen and when blue detected put a closed-eyed expression on screen (the code is shown below and all the code at 
https://makecode.com/_016aUf2YtDx6 might need to change it to blocks by changing a tab at the top of the screen)




Opinion.

I like Makecode anyway, but I think this is another good use of it. There is no installation needed to run the code and simulator and no LEGO has to be bought. If you have a Mindstorms EV3 kit, you can download your code to a physical EV3 robot (or whatever you have built using EV3). I would love to see in the comments what people have done with it as well.

Play with it yourself below:






The code used is available at https://makecode.com/_016aUf2YtDx6 


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

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 wa...