0% found this document useful (0 votes)
4 views3 pages

Micropython Cpython Notes Rpi Esp32

The document provides an overview of MicroPython and CPython for hardware control, detailing how to control GPIO pins on microcontrollers and Raspberry Pi. It includes examples for LED control, digital input, PWM, and I2C communication in MicroPython, as well as similar functionalities in CPython using the RPi.GPIO library. A comparison table highlights the differences in function calls between Arduino C, MicroPython, and Raspberry Pi Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Micropython Cpython Notes Rpi Esp32

The document provides an overview of MicroPython and CPython for hardware control, detailing how to control GPIO pins on microcontrollers and Raspberry Pi. It includes examples for LED control, digital input, PWM, and I2C communication in MicroPython, as well as similar functionalities in CPython using the RPi.GPIO library. A comparison table highlights the differences in function calls between Arduino C, MicroPython, and Raspberry Pi Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MicroPython and CPython (Raspberry Pi) – Basic

Hardware Control Notes

1. MicroPython Overview
MicroPython is a lightweight implementation of Python designed for microcontrollers
like ESP32 and ESP8266.
It allows direct hardware control using modules such as machine.

Import Hardware Modules


from machine import Pin
import time

Pin Control (Output)


from machine import Pin
led = Pin(2, [Link])

LED Control
[Link]()
[Link]()
# Alternative
[Link](1)
[Link](0)

Digital Input
button = Pin(4, [Link])
value = [Link]()

Delay
import time
[Link](1)

ADC (Analog Read)


from machine import ADC, Pin
adc = ADC(Pin(34))
value = [Link]()

PWM Example
from machine import Pin, PWM
pwm = PWM(Pin(2))
[Link](1000)
[Link](512)
I2C Example
from machine import I2C, Pin
i2c = I2C(0, scl=Pin(22), sda=Pin(21))

UART Example
from machine import UART
uart = UART(2, baudrate=9600)

LED Blink (MicroPython)


from machine import Pin
import time
led = Pin(2, [Link])
while True:
[Link]()
[Link](1)
[Link]()
[Link](1)

2. CPython on Raspberry Pi Overview


CPython is the standard Python interpreter used on computers and on Raspberry Pi.
GPIO pins are controlled using the [Link] library.

Import Library
import [Link] as GPIO
import time

Pin Numbering
[Link]([Link])

Set Output Pin


[Link](17, [Link])

LED Control
[Link](17, True)
[Link](17, False)

Digital Input
[Link](4, [Link])
value = [Link](4)

Delay
[Link](1)
PWM Example
pwm = [Link](17, 1000)
[Link](50)

LED Blink (Raspberry Pi)


import [Link] as GPIO
import time
[Link]([Link])
[Link](17, [Link])
while True:
[Link](17, True)
[Link](1)
[Link](17, False)
[Link](1)

Arduino vs MicroPython vs Raspberry Pi Python

Function Arduino C MicroPython Raspberry Pi Python


pinMode pinMode() Pin() [Link]()
digitalWrite digitalWrite() [Link]()/value() [Link]()
digitalRead digitalRead() [Link]() [Link]()
delay delay() [Link]() [Link]()
analogRead analogRead() [Link]() External ADC required

You might also like