mbed API for Raspberry Pi boards.
mbedPi
This is an attempt to implement a limited number of mbed APIs for Raspberry Pi single-board computers. The project was inspired by and based on the arduPi library developed for the Arduino by Cooking Hacks .
Specifications
- Chip: Broadcom BCM2836 SoC
- Core architecture: Quad-core ARM Cortex-A7
- CPU frequency: 900 MHz
- GPU: Dual Core VideoCore IV® Multimedia Co-Processor
- Memory: 1GB LPDDR2
- Operating System: Boots from Micro SD card, running a version of the Linux operating system
- Power: Micro USB socket 5V, 2A
Connectors
- Ethernet: 10/100 BaseT Ethernet socket
- Video Output: HDMI (rev 1.3 & 1.4)
- Audio Output: 3.5mm jack, HDMI
- USB: 4 x USB 2.0 Connector
- GPIO Connector: 40-pin 2.54 mm (100 mil) expansion header: 2x20 strip providing 27 GPIO pins as well as +3.3 V, +5 V and GND supply lines
- Camera Connector: 15-pin MIPI Camera Serial Interface (CSI-2)
- JTAG: Not populated
- Display Connector: Display Serial Interface (DSI) 15 way flat flex cable connector with two data lanes and a clock lane
- Memory Card Slot: Micro SDIO
GPIO connector pinout
Information
Only the labels printed in blue/white or green/white (i.e. p3, gpio2 ...) must be used in your code. The other labels are given as information (alternate-functions, power pins, ...).
Building programs for the Raspberry Pi with mbedPi
I use Qt Creator for development, however you can use any other IDE available on the Raspberry Pi (e.g. Geany) if you like. For a quick try:
- Install Qt and the Qt Creator onto your Raspberry Pi. Then create a new "Blinky" Plain non-Qt C++ Project as follows:
- Change the main code as below:
main.cpp
#include "mbedPi.h" int main() { DigitalOut myled(p7); while(1) { myled = 1; // LED is ON wait(0.2); // 200 ms myled = 0; // LED is OFF wait(1.0); // 1 sec printf("Blink\r\n"); } }
- Copy the mbedPi.zip file into your project's folder and unzip.
- Add the mbedPi.h and mbedPi.cpp files to your project by right clicking on the "Blinky" project and then clicking on the "Add Existing Files..." option in the local menu:
- Double click on Blinky.pro to open it for editing and add new libraries by inserting a new line as follows:
- Compile the project.
- Connect an LED through a 1k resistor to pin 7 and the ground on the Raspberry Pi GPIO connector.
- Run the binary as sudo (sudo ./Blinky) and you should see the LED blinking.
- Press Ctrl+c to stop running the application.
rpi_wizard/qbs_rpi/js/helpers.js@1:1f2d9982fa8c, 21 months ago (annotated)
- Committer:
- hudakz
- Date:
- Tue Dec 20 12:08:07 2022 +0000
- Revision:
- 1:1f2d9982fa8c
mbed API for Raspberry Pi boards equipped with BCM2836 SoC.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 1:1f2d9982fa8c | 1 | var Process = require("qbs.Process"); |
hudakz | 1:1f2d9982fa8c | 2 | var File = require("qbs.File"); |
hudakz | 1:1f2d9982fa8c | 3 | |
hudakz | 1:1f2d9982fa8c | 4 | function findCommand(){ |
hudakz | 1:1f2d9982fa8c | 5 | // check if it's unix |
hudakz | 1:1f2d9982fa8c | 6 | if(File.exists("/usr/bin/find")){ |
hudakz | 1:1f2d9982fa8c | 7 | return "/usr/bin/find"; |
hudakz | 1:1f2d9982fa8c | 8 | } |
hudakz | 1:1f2d9982fa8c | 9 | |
hudakz | 1:1f2d9982fa8c | 10 | // else msys2, search unix find command |
hudakz | 1:1f2d9982fa8c | 11 | var where = new Process(); |
hudakz | 1:1f2d9982fa8c | 12 | where.exec("where.exe", ['find'], true); |
hudakz | 1:1f2d9982fa8c | 13 | if(where.exitCode()!==0){ |
hudakz | 1:1f2d9982fa8c | 14 | throw("error: There is a problem to detect the 'find' command."+where.exitCode()); |
hudakz | 1:1f2d9982fa8c | 15 | } |
hudakz | 1:1f2d9982fa8c | 16 | |
hudakz | 1:1f2d9982fa8c | 17 | while(true){ |
hudakz | 1:1f2d9982fa8c | 18 | var line = where.readLine(); |
hudakz | 1:1f2d9982fa8c | 19 | if(line!=="" && line!==undefined){ |
hudakz | 1:1f2d9982fa8c | 20 | var findPos = line.indexOf("bin\\find.exe"); |
hudakz | 1:1f2d9982fa8c | 21 | if (findPos > -1){ |
hudakz | 1:1f2d9982fa8c | 22 | return line; |
hudakz | 1:1f2d9982fa8c | 23 | } |
hudakz | 1:1f2d9982fa8c | 24 | }else{ |
hudakz | 1:1f2d9982fa8c | 25 | break; |
hudakz | 1:1f2d9982fa8c | 26 | } |
hudakz | 1:1f2d9982fa8c | 27 | } |
hudakz | 1:1f2d9982fa8c | 28 | where.close() |
hudakz | 1:1f2d9982fa8c | 29 | return "find"; |
hudakz | 1:1f2d9982fa8c | 30 | } |
hudakz | 1:1f2d9982fa8c | 31 | |
hudakz | 1:1f2d9982fa8c | 32 | function dirs(dir){ |
hudakz | 1:1f2d9982fa8c | 33 | var ret = [] |
hudakz | 1:1f2d9982fa8c | 34 | if(!File.exists(dir)){ |
hudakz | 1:1f2d9982fa8c | 35 | return ret; |
hudakz | 1:1f2d9982fa8c | 36 | } |
hudakz | 1:1f2d9982fa8c | 37 | var find = new Process(); |
hudakz | 1:1f2d9982fa8c | 38 | var params = [dir,'-type','d']; |
hudakz | 1:1f2d9982fa8c | 39 | find.exec(findCommand(), params) |
hudakz | 1:1f2d9982fa8c | 40 | if(find.exitCode()!==0){ |
hudakz | 1:1f2d9982fa8c | 41 | var error = find.readStdErr(); |
hudakz | 1:1f2d9982fa8c | 42 | throw("error: " + error) |
hudakz | 1:1f2d9982fa8c | 43 | } |
hudakz | 1:1f2d9982fa8c | 44 | var line = find.readLine(); |
hudakz | 1:1f2d9982fa8c | 45 | while(line.trim()!==""){ |
hudakz | 1:1f2d9982fa8c | 46 | ret = ret.concat([line.trim()]); |
hudakz | 1:1f2d9982fa8c | 47 | line = find.readLine(); |
hudakz | 1:1f2d9982fa8c | 48 | } |
hudakz | 1:1f2d9982fa8c | 49 | find.close(); |
hudakz | 1:1f2d9982fa8c | 50 | return(ret) |
hudakz | 1:1f2d9982fa8c | 51 | } |
hudakz | 1:1f2d9982fa8c | 52 | |
hudakz | 1:1f2d9982fa8c | 53 | function getTimes() { |
hudakz | 1:1f2d9982fa8c | 54 | var d = new Date() |
hudakz | 1:1f2d9982fa8c | 55 | var current = d.getTime()/1000 // To seconds |
hudakz | 1:1f2d9982fa8c | 56 | var timezone = d.getTimezoneOffset()*60 // To seconds |
hudakz | 1:1f2d9982fa8c | 57 | var daylight = 0 |
hudakz | 1:1f2d9982fa8c | 58 | |
hudakz | 1:1f2d9982fa8c | 59 | return {"utc":current.toFixed(), |
hudakz | 1:1f2d9982fa8c | 60 | "local":(current+timezone+daylight).toFixed(), |
hudakz | 1:1f2d9982fa8c | 61 | "zone":timezone.toFixed(), |
hudakz | 1:1f2d9982fa8c | 62 | "dst":daylight.toFixed()} |
hudakz | 1:1f2d9982fa8c | 63 | } |
hudakz | 1:1f2d9982fa8c | 64 | |
hudakz | 1:1f2d9982fa8c | 65 |