You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Contributing to Raspberry Pi Pico C/C++ Examples
2
+
3
+
## How to Report a Bug
4
+
5
+
We use GitHub to host code, track [issues](https://github.com/raspberrypi/pico-examples/issues) and feature requests, and to accept [pull requests](https://github.com/raspberrypi/pico-examples/pulls). If you find think you have found a bug, please report it by [opening a new issue](https://github.com/raspberrypi/pico-examples/issues/new). Please include as much detail as possible, and ideally some code to reproduce the problem.
6
+
7
+
## How to Contribute Code
8
+
9
+
In order to contribute new or updated code, you must first create a GitHub account and fork the original repository to your own account. You can make changes, save them in your repository, then [make a pull request](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) against this repository. The pull request will appear [in the repository](https://github.com/raspberrypi/pico-examples/pulls) where it can be assessed by the maintainers, and if appropriate, merged with the official repository.
10
+
11
+
**NOTE:** Development takes place on the `develop` branch in this repository. Please open your https://github.com/raspberrypi/pico-examples/pulls[pull request] (PR) against the [`develop`](https://github.com/raspberrypi/pico-examples/tree/develop) branch, pull requests against the `master` branch will automatically CI fail checks and will not be accepted. You will be asked to rebase your PR against `develop` and if you do not do so, your PR will be closed.
12
+
13
+
### Code Style
14
+
15
+
If you are contributing new or updated code please match the existing code style, particularly:
16
+
17
+
* Use 4 spaces for indentation rather than tabs.
18
+
* Braces are required for everything except single line `if` statements.
19
+
* Opening braces should not be placed on a new line.
20
+
21
+
### Licensing
22
+
23
+
Code in this repository is lisensed under the [BSD-3 License](LICENSE.TXT). By contributing content to this repository you are agreeing to place your contributions under this licence.
Copy file name to clipboardExpand all lines: README.md
+27-2
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@ App|Description
20
20
[hello_adc](adc/hello_adc)|Display the voltage from an ADC input.
21
21
[joystick_display](adc/joystick_display)|Display a Joystick X/Y input based on two ADC inputs.
22
22
[adc_console](adc/adc_console)|An interactive shell for playing with the ADC. Includes example of free-running capture mode.
23
+
[microphone_adc](adc/microphone_adc)|Read analog values from a microphone and plot the measured sound amplitude.
23
24
24
25
### Clocks
25
26
@@ -76,8 +77,16 @@ App|Description
76
77
App|Description
77
78
---|---
78
79
[bus_scan](i2c/bus_scan) | Scan the I2C bus for devices and display results.
80
+
[bmp280_i2c](i2c/bmp280_i2c) | Read and convert temperature and pressure data from a BMP280 sensor, attached to an I2C bus.
79
81
[lcd_1602_i2c](i2c/lcd_1602_i2c) | Display some text on a generic 16x2 character LCD display, via I2C.
82
+
[lis3dh_i2c](i2c/lis3dh_i2c) | Read acceleration and temperature value from a LIS3DH sensor via I2C
83
+
[mcp9808_i2c](i2c/mcp9808_i2c) | Read temperature, set limits and raise alerts when limits are surpassed.
84
+
[mma8451_i2c](i2c/mma8451_i2c) | Read acceleration from a MMA8451 accelerometer and set range and precision for the data.
85
+
[mpl3115a2_i2c](i2c/mpl3115a2_i2c) | Interface with an MPL3115A2 altimeter, exploring interrupts and advanced board features, via I2C.
80
86
[mpu6050_i2c](i2c/mpu6050_i2c) | Read acceleration and angular rate values from a MPU6050 accelerometer/gyro, attached to an I2C bus.
87
+
[oled_i2c](i2c/oled_i2c) | Convert and display a bitmap on a 128x32 SSD1306-driven OLED display
88
+
[pa1010d_i2c](i2c/pa1010d_i2c) | Read GPS location data, parse and display data via I2C.
89
+
[pcf8523_i2c](i2c/pcf8523_i2c) | Read time and date values from a real time clock. Set current time and alarms on it.
81
90
82
91
### Interpolator
83
92
@@ -109,13 +118,15 @@ App|Description
109
118
[differential_manchester](pio/differential_manchester)| Send and receive differential Manchester-encoded serial (BMC).
110
119
[hub75](pio/hub75)| Display an image on a 128x64 HUB75 RGB LED matrix.
111
120
[i2c](pio/i2c)| Scan an I2C bus.
121
+
[ir_nec](pio/ir_nec)| Sending and receiving IR (infra-red) codes using the PIO.
112
122
[logic_analyser](pio/logic_analyser)| Use PIO and DMA to capture a logic trace of some GPIOs, whilst a PWM unit is driving them.
113
123
[manchester_encoding](pio/manchester_encoding)| Send and receive Manchester-encoded serial.
114
124
[pio_blink](pio/pio_blink)| Set up some PIO state machines to blink LEDs at different frequencies, according to delay counts pushed into their FIFOs.
115
125
[pwm](pio/pwm)| Pulse width modulation on PIO. Use it to gradually fade the brightness of an LED.
116
126
[spi](pio/spi)| Use PIO to erase, program and read an external SPI flash chip. A second example runs a loopback test with all four CPHA/CPOL combinations.
117
127
[squarewave](pio/squarewave)| Drive a fast square wave onto a GPIO. This example accesses low-level PIO registers directly, instead of using the SDK functions.
118
128
[st7789_lcd](pio/st7789_lcd)| Set up PIO for 62.5 Mbps serial output, and use this to display a spinning image on a ST7789 serial LCD.
129
+
[quadrature_encoder](pio/quadrature_encoder)| A quadrature encoder using PIO to maintain counts independent of the CPU.
119
130
[uart_rx](pio/uart_rx)| Implement the receive component of a UART serial port. Attach it to the spare Arm UART to see it receive characters.
120
131
[uart_tx](pio/uart_tx)| Implement the transmit component of a UART serial port, and print hello world.
121
132
[ws2812](pio/ws2812)| Examples of driving WS2812 addressable RGB LEDs.
@@ -172,13 +183,14 @@ App|Description
172
183
App|Description
173
184
---|---
174
185
[hello_uart](uart/hello_uart) | Print some text from one of the UART serial ports, without going through `stdio`.
186
+
[lcd_uart](uart/lcd_uart) | Display text and symbols on a 16x02 RGB LCD display via UART
175
187
[uart_advanced](uart/uart_advanced) | Use some other UART features like RX interrupts, hardware control flow, and data formats other than 8n1.
176
188
177
189
### USB Device
178
190
179
191
#### TinyUSB Examples
180
192
181
-
All but one of the USB device examples come directly from the TinyUSB device examples directory [here](https://github.com/hathach/tinyusb/tree/master/examples/device).
193
+
Most of the USB device examples come directly from the TinyUSB device examples directory [here](https://github.com/hathach/tinyusb/tree/master/examples/device).
182
194
Those that are supported on RP2040 devices are automatically included as part of the pico-examples
183
195
build as targets named `tinyusb_dev_<example_name>`, e.g. https://github.com/hathach/tinyusb/tree/master/examples/device/hid_composite
184
196
is built as `tinyusb_dev_hid_composite`.
@@ -198,11 +210,24 @@ At the time of writing, these examples are available:
198
210
- tinyusb_dev_hid_multiple_interface
199
211
- tinyusb_dev_midi_test
200
212
- tinyusb_dev_msc_dual_lun
213
+
- tinyusb_dev_net_lwip_webserver
201
214
- tinyusb_dev_uac2_headset
202
215
- tinyusb_dev_usbtmc
216
+
- tinyusb_dev_video_capture
203
217
- tinyusb_dev_webusb_serial
204
218
205
-
#### Low Level examples
219
+
Whilst these examples ably demonstrate how to use TinyUSB in device mode, their `CMakeLists.txt` is set up in a way
220
+
tailored to how TinyUSB builds their examples within their source tree.
221
+
222
+
For a better example of how to configure `CMakeLists.txt` for using TinyUSB in device mode with the Raspberry Pi SDK
223
+
see below:
224
+
225
+
#### SDK build example
226
+
App|Description
227
+
---|---
228
+
[dev_hid_composite](usb/device/dev_hid_composite) | A copy of the TinyUSB device example with the same name, but with a CMakeLists.txt which demonstrates how to add a dependency on the TinyUSB device libraries with the Raspberry Pi Pico SDK
229
+
230
+
#### Low Level example
206
231
App|Description
207
232
---|---
208
233
[dev_lowlevel](usb/device/dev_lowlevel) | A USB Bulk loopback implemented with direct access to the USB hardware (no TinyUSB)
This example code shows how to interface the Raspberry Pi Pico with a standard analog microphone via the onboard analog to digital converter (ADC). In this example, we use an ICS-40180 breakout board by SparkFun but any analog microphone should be compatible with this tutorial. SparkFun have https://learn.sparkfun.com/tutorials/mems-microphone-hookup-guide[written a guide] for this board that goes into more detail about the board and how it works.
4
+
5
+
[TIP]
6
+
======
7
+
An analog to digital converter (ADC) is responsible for reading continually varying input signals that may range from 0 to a specified reference voltage (in the Pico's case this reference voltage is set by the supply voltage and can be measured on pin 35, ADC_VREF) and converting them into binary, i.e. a number that can be digitally stored.
8
+
======
9
+
10
+
The Pico has a 12-bit ADC (ENOB of 8.7-bit, see https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf[RP2040 datasheet section 4.9.3 for more details]), meaning that a read operation will return a number ranging from 0 to 4095 (2^12 - 1) for a total of 4096 possible values. Therefore, the resolution of the ADC is 3.3/4096, so roughly steps of 0.8 millivolts. The SparkFun breakout uses an OPA344 operational amplifier to boost the signal coming from the microphone to voltage levels that can be easily read by the ADC. An important side effect is that a bias of 0.5*Vcc is added to the signal, even when the microphone is not picking up any sound.
11
+
12
+
The ADC provides us with a raw voltage value but when dealing with sound, we're more interested in the amplitude of the audio signal. This is defined as one half the peak-to-peak amplitude. Included with this example is a very simple Python script that will plot the voltage values it receives via the serial port. By tweaking the sampling rates, and various other parameters, the data from the microphone can be analysed in various ways, such as in a Fast Fourier Transform to see what frequencies make up the signal.
13
+
14
+
[[microphone_adc_plotter_image]]
15
+
[pdfwidth=75%]
16
+
.Example output from included Python script
17
+
image::microphone_adc_plotter.png[]
18
+
19
+
== Wiring information
20
+
21
+
Wiring up the device requires 3 jumpers, to connect VCC (3.3v), GND, and AOUT. The example here uses ADC0, which is GP26. Power is supplied from the 3.3V pin.
22
+
23
+
WARNING: Most boards will take a range of VCC voltages from the Pico's default 3.3V to the 5 volts commonly seen on other microcontrollers. Ensure your board doesn't output an analogue signal greater than 3.3V as this may result in permanent damage to the Pico's ADC.
24
+
25
+
[[ics-40180-adc_wiring]]
26
+
[pdfwidth=75%]
27
+
.Wiring Diagram for ICS-40180 microphone breakout board.
28
+
image::microphone_adc_bb.png[]
29
+
30
+
== List of Files
31
+
32
+
CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree.
33
+
microphone_adc.c:: The example code.
34
+
35
+
== Bill of Materials
36
+
37
+
.A list of materials required for the example
38
+
[[ics-40180-adc-bom-table]]
39
+
[cols=3]
40
+
|===
41
+
| *Item* | *Quantity* | Details
42
+
| Breadboard | 1 | generic part
43
+
| Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/
44
+
| ICS-40180 microphone breakout board or similar | 1 | https://www.sparkfun.com/products/18011[From SparkFun]
0 commit comments