Difference between revisions of "BeagleBoard/GSoC/2021 Proposal/Micropython for BeagleConnect Freedom"

From eLinux.org
Jump to: navigation, search
(26 intermediate revisions by the same user not shown)
Line 33: Line 33:
  
 
===Description===
 
===Description===
Enable Micropython for BeagleConnect Freedom along with basic GPIO, I2C, SPI, PWM, ADC drivers.
+
The goal of this project is to enable Micropython for BeagleConnect Freedom along with basic GPIO, I2C, SPI, PWM, ADC drivers. MicroPython is a C implementation of the widely known and used Python3 language aimed specifically to run on a microcontroller. A ported MicroPython would allow for easy out-of-the-box development and prototyping with BeagleConnect Freedom, Python being an easy to learn and use language, with powerful capabilities at the same time being very concise.
In 10-20 sentences, what are you making, for whom, why and with what technologies (programming languages, etc.)? (We are looking for open source SOFTWARE submissions.)
+
The drivers would be written in C as an extension and interface to MicroPython. The port itself along with additional extensions would be based on the official documentation by MicroPython for [https://docs.micropython.org/en/latest/develop/porting.html porting the language]. Additionally after the MicroPython port and writing the basic drivers I could test them in practice using the supported MikroElectronika boards.  
  
 +
// Should CircuitPython also be ported to be more newbie-friendly, if porting MicroPython proves to be rather quick?
 +
 +
===Implementation===
 +
====Porting MicroPython====
 +
// Does the current port of MicroPython for Zephyr build correctly for BeagleConnect Freedom? (I assume it already has working drivers that Zephyr on Beagle can communicate with the MCU and use I2C SPI and GPIO)
 +
 +
// What other modules should be added to the minimal version of MicroPython? (Is GPIO, I2C SPI PWM and ADC all that would be necessary?)
 +
 +
Before doing anything else, MicroPython itself needs to be ported to work on Zephyr RTOS and the BealgeConnect Freedom itself, as the rest of the project relies on a working ported version of it. A [https://github.com/micropython/micropython/tree/master/ports/zephyr work-in-progress port for Zephyr] would be the starting point for this part of the project. Ensuring that a [https://docs.micropython.org/en/latest/develop/porting.html minimal build with a simple REPL loop] can be built and run on the BeagleConnect board would be the next step.
 +
 +
====Writing drivers====
 +
The basic drivers required by this project include GPIO, I2C, SPI, PWM and ADC, since they would allow many sensors interfacing with the BeagleConnect Freedom to be programmable and utilised via MicroPython. As Python in general is more space and time hungry than C, and given we have limited resources on the microcontroller, it is logical to write those basic drivers in C and create MicroPython interfaces for them.
 +
 +
In the current [https://github.com/micropython/micropython/tree/master/ports/zephyr port of MicroPython for Zephyr] a MicroPython module '''machine''' is already implemented with some basic submodules and functionalities for I2C and GPIO. Therefore these modules would need to be extended or rewritten to be able to interface with BeagleConnect Freedom as well as additional such drivers would be implemented for SPI, PWM and ADC.
 +
 +
The BeagleConnect Freedom uses [https://lwn.net/Articles/715955/ Greybus] to communicate with connected devices, so a possible approach would be to make the drivers communicate through Greybus. An alternative solution would be to communicate with GPIO pins directly, which is the main goal.
 +
 +
The graph below is a visualisation of the implementation of basic drivers and their interface with MicroPython on one end, and Zephyr RTOS on the other.
 +
 +
[[File:Module-structure.jpeg| Visualisation of basic driver structure as submodules for MicroPython and interface with Zephyr]]
 +
 +
Below is a rough implementation plan for each of the drivers and how they will interact with BeagleConnect Freedom. All these drivers will be submodules of the '''machine''' module. Minimal MicroPython constructors are listed under each driver. These requirements are based on the actual implementation of [https://docs.micropython.org/en/latest/library/machine.html those modules in MicroPython].
 +
=====GPIO Module=====
 +
 +
The GPIO driver should allow developers to manipulate and read from GPIO pins on the BeagleConnect Freedom. More detailed explanation of necessary functions and constructors can be found on [https://docs.micropython.org/en/latest/library/machine.Pin.html MicroPythons documentation] for GPIO module.
 +
// todo How can microPython interface with the GPIO pinout on the BeagleConnect Freedom?
 +
 +
=====I2C Module=====
 +
 +
The I2C module allows for 2 wire communication using the [https://en.wikipedia.org/wiki/I%C2%B2C I2C protocol]. This should allow for software and hardware I2C connections. As a minimum, this module should have:
 +
* I2C constructor:
 +
where scl is a pin object of the Clock pin,
 +
sda is a pin object of the Data pin, frequency is an integer defining the maxiximum frequency of the clock SCL,
 +
timeout is the maximum time in microsecods to wait for the clock stretching (SCL being held low by another device on that bus).
 +
<source lang=python>
 +
class machine.I2C(scl, sda, frequency, timeout)
 +
</source>
 +
*
 +
=====SPI Module=====
 +
 +
=====PWM Module=====
 +
 +
=====ADC Module=====
 +
 +
===Possible extensions to the project===
 +
====CircuitPython port====
 +
After successfully completing a MicroPython port for the BeagleConnect Freedom and writing the minimal drivers, porting CircuitPython would be a good addition. Although CircuitPython is far less advanced than MicroPython, it is more newbie-friendly. This would allow beginners easier entry to the world of IOT and for experimenting with the BeagleConnect.
 +
 +
====Adding more MicroPython modules to work with the BeagleConnect Freedom====
 +
There are many libraries (modules) implemented in the core version of MicroPython, ranging from libraries derived from original Python3 core libraries to MicroPython-specific libraries (such as '''machine''' module). Adding some of those libraries would give more possibilities when developing on BeagleConnect Freedom using MicroPython. An example would be to implement [https://docs.micropython.org/en/latest/library/ubluetooth.html ubluetooth] library which could be used by the BeagleConnect node device.
 +
 +
====Rewriting the drivers to communicate via Greybus====
 +
Although I have not met Greybus before, after reading about it, it seems like writing the drivers to communicate using them could be a good idea, as BeagleConnect already utilities it.
 +
// todo fact check this^ (Or is it just planning to use Greybus?)
 +
This could prove to be useful when communicating between the BeagleConnect gateway device and the node device.
 +
// todo Rethink how exactly can it come in handy?
 
===Timeline===
 
===Timeline===
 
Provide a development timeline with a milestone each of the 11 weeks and any pre-work. (A realistic timeline is critical to our selection process.)
 
Provide a development timeline with a milestone each of the 11 weeks and any pre-work. (A realistic timeline is critical to our selection process.)
 
 
{| class="wikitable"
 
{| class="wikitable"
| Mar 29 || Applications open, Students register with GSoC, work on proposal with mentors
 
|-
 
| Apr 13 || Proposal complete, Submitted to https://summerofcode.withgoogle.com
 
 
|-
 
|-
| May 17 || Proposal accepted or rejected
+
! Date !!  Milestone !! Action Items
 
|-
 
|-
| Jun 07 || Pre-work complete, Coding officially begins!
+
| 13.04.21-17.05.21 || Pre-work ||
 +
* Getting familiar with Zephyr RTOS and [https://www.ti.com/tool/LAUNCHXL-CC1352R1 SimpleLink™ Multi-Band CC1352R Wireless MCU LaunchPad™ Development Kit] specification.
 +
* Order parts necessary for module testing
 
|-
 
|-
| Jun 17 || Milestone #1, Introductory YouTube video
+
| 07.06.21 || Coding Start! ||
 +
* Introductory YouTube video
 +
* Port minimal MicroPython
 +
* Experiment with BeagleConnect Freedom
 
|-
 
|-
| June 24 || Milestone #2
+
| 17.06.21 || Milestone #1 ||
 +
* Complete the GPIO module
 +
* Test the GPIO module
 +
* Document the progress in a blog post
 
|-
 
|-
| June 30 || Milestone #3
+
| 24.07.21 || Milestone #2 ||
 +
* Complete the I2C module
 +
* Test the I2C module
 
|-
 
|-
| July 12 18:00 UTC || Milestone #4, Mentors and students can begin submitting Phase 1 evaluations
+
| 30.06.21 || Milestone #3 ||
 +
* Complete the SPI module
 +
* Test the SPI module
 +
* Document the progress in a blog post
 
|-
 
|-
| July 16 18:00 UTC || Phase 1 Evaluation deadline
+
| 12.07.21 || Milestone #4 ||
 +
* Complete the PWM module
 +
* Test the PWM module
 
|-
 
|-
| July 23 || Milestone #5
+
| 23.07.21 || Milestone #5 ||
 +
* Complete the ADC module
 +
* Test the ADC module
 +
* Document the progress in a blog post
 
|-
 
|-
| July 30 || Milestone #6
+
| 23.07.21 || Milestone #6 ||
 +
* Polish the current MicroPython port
 +
* Polish each module and retest
 
|-
 
|-
| Aug 06 || Milestone #7
+
| 6.8.21 || Milestone #7 ||
 +
* Implement extensions to the project:
 +
* Port CircuitPython to BeagleConnect Freedom
 +
* Test the ported CircuitPython
 +
* Document the progress in a blog post
 
|-
 
|-
| August 10 || Milestone #8, Completion YouTube video
+
| 10.8.21 || Milestone #8 ||
 +
* Implement extensions to the project:
 +
* Add more MicroPython modules to work with BeagleConnect Freedom (e.g. [https://docs.micropython.org/en/latest/library/ubluetooth.html ubluetooth])
 +
* Record completion YouTube video
 
|-
 
|-
| August 16 - 26 18:00 UTC || Final week: Students submit their final work product and their final mentor evaluation
+
| 24.08.21 || Feedback time ||
 +
* Complete feedback form for the mentor
 
|-
 
|-
| August 23 - 30 18:00 UTC || Mentors submit final student evaluations
+
| 31.08.21 || Results announced ||
 +
* Celebrate the ending and rejoice
 
|}
 
|}
  
Line 75: Line 156:
  
 
===Contingency===
 
===Contingency===
What will you do if you get stuck on your project and your mentor isn’t around?
+
Since the project requires mostly individual work on the project, I will make sure to get in touch with the BeagleBoard community to get feedback/help from more experienced developers if my mentor is not available. Additionally there is plenty of information to help me out already available in [https://docs.micropython.org/en/latest/develop/porting.html MicroPython documentation] as to how porting should be done and many [https://github.com/micropython/micropython/blob/master/ports examples of already complete ports] on MicroPython's github.
 +
// todo add more on driver development and contingencies for that
  
 
===Benefit===
 
===Benefit===
Line 81: Line 163:
  
 
==Misc==
 
==Misc==
Please complete the requirements listed on the [[BeagleBoard/GSoC/Ideas#General_requirements|ideas page]]. Provide link to pull request.
+
Pull request required for qualification can be found [https://github.com/jadonk/gsoc-application/pull/156 here].
  
 
===Suggestions===
 
===Suggestions===
 
Is there anything else we should have asked you?
 
Is there anything else we should have asked you?

Revision as of 13:48, 12 April 2021


[Micropython for BeagleConnect Freedom]

About Student: Szymon Duchniewicz
Mentors: Jason Kridner
Code: No code just yet
Wiki: https://elinux.org/BeagleBoard/GSoC/2021_Proposal/Micropython_for_BeagleConnect_Freedom
GSoC: GSoC entry

Status

This project is currently just a proposal.

Proposal

Please complete the requirements listed on the ideas page and fill out this template.

About you

IRC: Willmish
Github: Willmish
School: University College London
Country: United Kingdom/Poland
Primary language: Polish
Typical work hours: 8AM-5PM CET
Previous GSoC participation: I haven't participated before in GSoC but I am very intrigued by the idea of being able to work with an Open Source organization, as I always wanted to get involved with Open Source and this looks like a great place to start! Furthermore, I believe that through this project I could develop my current skill-set substantially both in software and hardware domains. As I have some previous experience in working with embedded systems such as Arduino and Rpi and programming them in Python, I thought that the idea of bringing Micropython to BeagleConnect Freedom is great and would fit my current capabilities quite well, while also posing an interesting challenge!

About your project

Project name: Micropython for BeagleConnect Freedom

Description

The goal of this project is to enable Micropython for BeagleConnect Freedom along with basic GPIO, I2C, SPI, PWM, ADC drivers. MicroPython is a C implementation of the widely known and used Python3 language aimed specifically to run on a microcontroller. A ported MicroPython would allow for easy out-of-the-box development and prototyping with BeagleConnect Freedom, Python being an easy to learn and use language, with powerful capabilities at the same time being very concise. The drivers would be written in C as an extension and interface to MicroPython. The port itself along with additional extensions would be based on the official documentation by MicroPython for porting the language. Additionally after the MicroPython port and writing the basic drivers I could test them in practice using the supported MikroElectronika boards.

// Should CircuitPython also be ported to be more newbie-friendly, if porting MicroPython proves to be rather quick?

Implementation

Porting MicroPython

// Does the current port of MicroPython for Zephyr build correctly for BeagleConnect Freedom? (I assume it already has working drivers that Zephyr on Beagle can communicate with the MCU and use I2C SPI and GPIO)

// What other modules should be added to the minimal version of MicroPython? (Is GPIO, I2C SPI PWM and ADC all that would be necessary?)

Before doing anything else, MicroPython itself needs to be ported to work on Zephyr RTOS and the BealgeConnect Freedom itself, as the rest of the project relies on a working ported version of it. A work-in-progress port for Zephyr would be the starting point for this part of the project. Ensuring that a minimal build with a simple REPL loop can be built and run on the BeagleConnect board would be the next step.

Writing drivers

The basic drivers required by this project include GPIO, I2C, SPI, PWM and ADC, since they would allow many sensors interfacing with the BeagleConnect Freedom to be programmable and utilised via MicroPython. As Python in general is more space and time hungry than C, and given we have limited resources on the microcontroller, it is logical to write those basic drivers in C and create MicroPython interfaces for them.

In the current port of MicroPython for Zephyr a MicroPython module machine is already implemented with some basic submodules and functionalities for I2C and GPIO. Therefore these modules would need to be extended or rewritten to be able to interface with BeagleConnect Freedom as well as additional such drivers would be implemented for SPI, PWM and ADC.

The BeagleConnect Freedom uses Greybus to communicate with connected devices, so a possible approach would be to make the drivers communicate through Greybus. An alternative solution would be to communicate with GPIO pins directly, which is the main goal.

The graph below is a visualisation of the implementation of basic drivers and their interface with MicroPython on one end, and Zephyr RTOS on the other.

Visualisation of basic driver structure as submodules for MicroPython and interface with Zephyr

Below is a rough implementation plan for each of the drivers and how they will interact with BeagleConnect Freedom. All these drivers will be submodules of the machine module. Minimal MicroPython constructors are listed under each driver. These requirements are based on the actual implementation of those modules in MicroPython.

GPIO Module

The GPIO driver should allow developers to manipulate and read from GPIO pins on the BeagleConnect Freedom. More detailed explanation of necessary functions and constructors can be found on MicroPythons documentation for GPIO module. // todo How can microPython interface with the GPIO pinout on the BeagleConnect Freedom?

I2C Module

The I2C module allows for 2 wire communication using the I2C protocol. This should allow for software and hardware I2C connections. As a minimum, this module should have:

  • I2C constructor:

where scl is a pin object of the Clock pin, sda is a pin object of the Data pin, frequency is an integer defining the maxiximum frequency of the clock SCL, timeout is the maximum time in microsecods to wait for the clock stretching (SCL being held low by another device on that bus).

class machine.I2C(scl, sda, frequency, timeout)
SPI Module
PWM Module
ADC Module

Possible extensions to the project

CircuitPython port

After successfully completing a MicroPython port for the BeagleConnect Freedom and writing the minimal drivers, porting CircuitPython would be a good addition. Although CircuitPython is far less advanced than MicroPython, it is more newbie-friendly. This would allow beginners easier entry to the world of IOT and for experimenting with the BeagleConnect.

Adding more MicroPython modules to work with the BeagleConnect Freedom

There are many libraries (modules) implemented in the core version of MicroPython, ranging from libraries derived from original Python3 core libraries to MicroPython-specific libraries (such as machine module). Adding some of those libraries would give more possibilities when developing on BeagleConnect Freedom using MicroPython. An example would be to implement ubluetooth library which could be used by the BeagleConnect node device.

Rewriting the drivers to communicate via Greybus

Although I have not met Greybus before, after reading about it, it seems like writing the drivers to communicate using them could be a good idea, as BeagleConnect already utilities it. // todo fact check this^ (Or is it just planning to use Greybus?)

This could prove to be useful when communicating between the BeagleConnect gateway device and the node device.
// todo Rethink how exactly can it come in handy?

Timeline

Provide a development timeline with a milestone each of the 11 weeks and any pre-work. (A realistic timeline is critical to our selection process.)

Date Milestone Action Items
13.04.21-17.05.21 Pre-work
07.06.21 Coding Start!
  • Introductory YouTube video
  • Port minimal MicroPython
  • Experiment with BeagleConnect Freedom
17.06.21 Milestone #1
  • Complete the GPIO module
  • Test the GPIO module
  • Document the progress in a blog post
24.07.21 Milestone #2
  • Complete the I2C module
  • Test the I2C module
30.06.21 Milestone #3
  • Complete the SPI module
  • Test the SPI module
  • Document the progress in a blog post
12.07.21 Milestone #4
  • Complete the PWM module
  • Test the PWM module
23.07.21 Milestone #5
  • Complete the ADC module
  • Test the ADC module
  • Document the progress in a blog post
23.07.21 Milestone #6
  • Polish the current MicroPython port
  • Polish each module and retest
6.8.21 Milestone #7
  • Implement extensions to the project:
  • Port CircuitPython to BeagleConnect Freedom
  • Test the ported CircuitPython
  • Document the progress in a blog post
10.8.21 Milestone #8
  • Implement extensions to the project:
  • Add more MicroPython modules to work with BeagleConnect Freedom (e.g. ubluetooth)
  • Record completion YouTube video
24.08.21 Feedback time
  • Complete feedback form for the mentor
31.08.21 Results announced
  • Celebrate the ending and rejoice

Experience and approach

In 5-15 sentences, convince us you will be able to successfully complete your project in the timeline you have described.

Contingency

Since the project requires mostly individual work on the project, I will make sure to get in touch with the BeagleBoard community to get feedback/help from more experienced developers if my mentor is not available. Additionally there is plenty of information to help me out already available in MicroPython documentation as to how porting should be done and many examples of already complete ports on MicroPython's github. // todo add more on driver development and contingencies for that

Benefit

If successfully completed, what will its impact be on the BeagleBoard.org community? Include quotes from BeagleBoard.org community members who can be found on http://beagleboard.org/discuss and http://bbb.io/gsocchat.

Misc

Pull request required for qualification can be found here.

Suggestions

Is there anything else we should have asked you?