top of page
Search

Project 1a - A Simple Neural Network (Pyboard) - XOR logic

  • Writer: James Canova
    James Canova
  • Sep 24, 2021
  • 2 min read

Updated: Apr 2, 2024

Project start: 1 July 2021

Project finish: 10 October 2021


Last updated: 30 March 2024


The main components of the project assembly are a Pyboard (V1.1.8) , one push button and two slider switches.


Pyboard Assembly

When the program starts, the neural network trains itself. A red LED stays on until training is complete then a green LED turns on. The two sliders are the inputs to the XOR routine. LEDs are used to display the result, which is either 0 (yellow LED) or 1 (blue LED). Training takes about 70[sec] (with learning rate = 0.08 and number of training epochs = 20,000) and a query is instantaneous.


Parts list:




Wiring diagram


Micropython installation on to Laptop/PC (host):


Install Micropython:


Check that Python 3 is installed (installed by default with Ubuntu):

$ python3 -V

Change to home directory:

$ cd $HOME

Clone Micropython from GitHub:

$ git clone https://github.com/micropython/micropython.git

Make:

$ cd micropython
$ cd mpy-cross
$ make

Add path to micropython binary to .bashrc file.


Test micropython:

# cd $HOME
$ micropython

Add the "ulab" module (includes numpy for matrix operations) to Micropython:


Check that GCC is installed:

$ gcc --version

Clone the ulab module from GitHub:

Make:

$ cd ports/stm32
$ make clean BOARD=PYBV11
$ make submodules
$ make BOARD=PYBV11 USER_C_MODULES=../../ulab all

Flash Micropython firmware that includes "ulab".


navigate to: ../micropython/ports/stm32/build-PYBV11


fit jumper (see schematic above)

sudo dfu-utils --alt 0 -D firmware.dfu 

remove jumper



The program for the neural network is called "main.py" (required).


It can be downloaded from my GitHub repository (please refer to the Internet if you need instruction):



Run Thonny from the command line:

$ thonny

Within Thonny, go to the "Run" menu then select, "Select interpreter..." and then select "Interpreter". Choose, "MicroPython (generic)" and "Pyboard Virtual Comm Port in FS Mode (/dev/tty/ACM0)".


Run the program in REPL mode:

Open main.py in Thonny and press the "run" button


Change the position of the slider switches and check results in the shell window in Thonny and watch the LED colour change.


Alteratively, copy and paste main.py onto the Pyboard using a file explorer. Push the reset button to run the program.



If you have any problems or need clarification please contact me: jscanova@gmail.com

















 
 
 

Recent Posts

See All
Introduction

I became interested in artificial intelligence in mid 2021 after watching a documentary on this subject. In particular, I'm interested in...

 
 
 
References

1.Rashid, Tariq, Make Your Own Neural Network , Amazon , 2016 2.Portilla, Jose, "Python for Computer Vision with OpenCV and Deep...

 
 
 
Status of Projects

Last updated: 30 March 2024 Project 0: Read this to get a very basic understating on machine learning and neural networks. Project 1:...

 
 
 

Comments


Post: Blog posts

©2021 by My Machine Learning Blog. Proudly created with Wix.com

bottom of page