Modifications

Sauter à la navigation Sauter à la recherche
1 717 octets ajoutés ,  7 mars 2022 à 14:16
Ligne 15 : Ligne 15 :     
Here follows some fundamentals help links about the Python language himself:
 
Here follows some fundamentals help links about the Python language himself:
* [https://www.w3schools.com/python/ '''W3Schools''' on Python] : one of the best resource for learning online.
+
* [https://www.w3schools.com/python/ '''W3Schools''' on Python] : one of the best ressource for learning online (should I say "my favorite one).
 
* [https://www.pythoncheatsheet.org/#Python-Basics '''P'''ython'''C'''heat'''S'''heet.org] : Anyone can forget how to make loop, list, dictionary, tuple, list slice, math operator, generator...
 
* [https://www.pythoncheatsheet.org/#Python-Basics '''P'''ython'''C'''heat'''S'''heet.org] : Anyone can forget how to make loop, list, dictionary, tuple, list slice, math operator, generator...
 
* [https://www.pythonsheets.com/ pythonsheets.com] : more advanced cheat sheet.
 
* [https://www.pythonsheets.com/ pythonsheets.com] : more advanced cheat sheet.
Ligne 114 : Ligne 114 :  
That method returns a 16 bits value, so a number between 0 and 65535.
 
That method returns a 16 bits value, so a number between 0 and 65535.
   −
{{ambox|text=Even if the {{fname|read_u16()}} returns a 16 bits values, the effective ADC resolution is still 12 bits. The MicroPython internal will just upscale the ADC value from 0..4095 to returned value 0..65535 by applying a multiplier.}}
+
{{ambox|text=Even if the {{fname|read_u16()}} returns a 16 bits values, the effective ADC resolution is still 12 bits. The MicroPython internal will just upscale the ADC value from 0..4095 to returned value 0..65535 by applying a multiplier.  
 +
 
 +
The effective ADC reading precision is 3.3V/4095 = 0.000805V (0.8mv) }}
    
[[Fichier:ENG-CANSAT-FEATHER-PICO-HowTo-25.png]]
 
[[Fichier:ENG-CANSAT-FEATHER-PICO-HowTo-25.png]]
Ligne 211 : Ligne 213 :  
The UART is often compared to a serial port (which is in facts very similar to).
 
The UART is often compared to a serial port (which is in facts very similar to).
   −
It allows to send and receives data from a device using the same interface like modem, GPS, termina. UART/Serial ports are used to creates point to point communication.
+
It allows to send and receives data from a device using the same interface like modem, GPS, terminal. UART/Serial ports are used to creates point to point communication.
   −
When wiring a UART, the RX & TX connection must be cross-over like the wiring to GPS here below.
+
When wiring an UART, the RX & TX connection must be cross-over like the wiring to GPS here below (see the [https://github.com/mchobby/esp8266-upy/tree/master/gps-ultimate gps-ultimate MicroPython library])
    
[[Fichier:ENG-CANSAT-PICO-HowTo-UART.png|480px]]
 
[[Fichier:ENG-CANSAT-PICO-HowTo-UART.png|480px]]
   −
{{ambox|text=It is advised to use the UART(1) on GP4 & GP5. Indeed, UART(0) is used to replicates REPL session. See the [[ENG-CANSAT-PICO-USER-GUIDE|Pinout]] for details.}}  
+
{{ambox|text=It is advised to use the UART(0) on GP0 & GP1. Indeed, UART(1) overlaps the SPI(0) used for Radio module. Alternative UART(1) position overlaps the I2C(0) bus. See the [[ENG-CANSAT-PICO-USER-GUIDE|Pinout]] for details.}}  
 +
 
 +
<syntaxhighlight lang="python">
 +
from machine import UART, Pin
 +
 
 +
# UART(0) on GP0 & GP1
 +
uart = UART( 0, baudrate=9600)
 +
 
 +
# UART(1) on GP4 & GP5
 +
uart = UART( 1, baudrate=9600, timeout=3000)
 +
 
 +
# Alternate position for UART(1) by using Bus Fabric feature
 +
uart = UART( 1, rx=Pin(9), tx=Pin(8), baudrate=9600 )
 +
</syntaxhighlight>
 +
 
 +
Outside of connecting device (like GPS) to the UART, you can also use an UART to get the REPL over it (exactly like USB connexion but over an UART. This may be kindly useful to bring a REPL connectivity over mobile network/device.
 +
 +
The following snip of code duplicates the REPL over the {{fname|UART(0)}} .
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
from machine import UART
 
from machine import UART
 +
from os import dupterm
   −
uart = UART( 1, baudrate=9600, timeout=3000)  
+
uart = UART(0, baudrate=19200, bits=8, parity=None, stop=1)
 +
os.dupterm( uart, 1 ) # Pico Firmware must be recompile with dupterm()
 
</syntaxhighlight>
 
</syntaxhighlight>
    
The {{fname|UART}} class is [https://docs.micropython.org/en/latest/library/machine.UART.html fully described into MicroPython documentation].
 
The {{fname|UART}} class is [https://docs.micropython.org/en/latest/library/machine.UART.html fully described into MicroPython documentation].
   −
One of the key parameter of UART is the {{fname|timeout}} parameter which indicates the timeout (in ms) to receive the end-of-line on {{fname|UART.readline()}} .
+
The {{fname|dupterm()}} function is [https://docs.micropython.org/en/latest/library/os.html#terminal-redirection-and-duplication described here into the MicroPython documentation].
 +
 
 +
{{underline|Tips & Tricks:}}
 +
* One of the key parameter of UART is the {{fname|timeout}} parameter which indicates the timeout (in ms) to receive the end-of-line on {{fname|UART.readline()}} .
 +
* See this [https://forums.raspberrypi.com/viewtopic.php?t=304410 Raspberry-Pi forum thread] to compile a dupterm() enabled firmware for Pico.
    
=== SPI Bus ===
 
=== SPI Bus ===
An SPI bus is high speed full duplex bus. High speed means several mega-hertz (can be up to +20 MHz). The full duplex means communicates in both direction at the same time.  
+
An SPI bus is high speed full duplex bus.  
 +
* High speed means several mega-hertz (can be up to +20 MHz).  
 +
* Full duplex means communicates in both direction at the same time.  
   −
SPI bus are very short (below 10cm) and use 3 wires for the data bus + a "Slave Select" wire per device:
+
Thanks to its high throughput, the SPI bus are used for display, data acquisition, data transmission, etc.
    +
{{ambox|text=The Cansat RFM69 Radio module of Cansat kit do use {{fname|SPI(0)}} bus to exchange data with the MicroControler.}}
   −
bus is a very popular serial bus in electronic to connect sensors and electronics to a microcontroler. Some DIY Maker companies did also use some "normalized" connectors around I2C bus. You may probably already ear words about Qwiic from SparkFun, StemmaQt from Adafruit (Qwiic compatible), Grove from SeeedStudio.
+
SPI bus are short (below 10cm) and uses '''3 wires for the data bus + a "Slave Select" wire per device''':
 +
* MOSI: Master Out Slave In. Communication from the microcontroler to the device.
 +
* MISO: Master In Slave Out. Communication from the device to the microcontroler.
 +
* SCLK: Clock signal giving the rythme to the data transfer.
 +
* SS: Slave Select (activated at LOW) used to activate the device on the bus. It is also used to start "transaction" with the device.  
   −
Maybe not the fastest bus, this bus is easy to wire and to manage and requires only 2 wires:
+
[[Fichier:ENG-CANSAT-PICO-HowTo-SPI.png]]
   −
    SDA: Serial Data
+
The following snip of code creates an instance of the {{fname|SPI(0)}} bus
    SCL: Serial Clock
+
<syntaxhighlight lang="python">
 +
from machine import Pin, SPI
   −
The I2C protocol use an address (0..127) to contact the target board with request and waiting for response. For sure each sensor boards must have an unique address on the I2C. On I2C implementation, the microcontroler do always keeps the control over the I2C communication.
+
ss = Pin( 5, Pin.OUT, value=1 ) # Slave Select in deactivated state by default.
 +
# SPI(0) : GP4=Miso, GP5=/SS, GP6=Sck, GP7=Mosi
 +
# reducing clock speed to 400 KHz
 +
spi = SPI( 0, baudrate=400000 )
 +
</syntaxhighlight>
   −
<syntaxhighlight lang="python">
+
{{underline|Tips & Tricks:}}<br />Under MicroPython the SS pin is not "hardware" tied to a given SPI bus. User can freely choose any pin as "Slave Select" pin.
from machine import Pin
  −
x
  −
x
  −
x
  −
x
  −
</syntaxhighlight>
      
== Additional tutorials ==
 
== Additional tutorials ==
29 917

modifications

Menu de navigation