Arduino

2022年2月 6日 (日)

platformioのために新しいユーザーを設定する

2022/2/7+
初版

new user for platformio

new user for platformio

概要

platformioのために新しいユーザーを設定する。
platformioを使用しているときに環境問題で動作が不良になったときがあり、
pythonの仮想環境をいったん消去してplatformioを再インストールしても 解決しなかったときがあった。
これを解決するために、新しいアカウントを作り、新しいユーザーを設定して、そこにログインして その環境にplatformioをインストールする。
ここでは、新しいアカウントを作る方法について記する。
(ubuntu-20.04を想定する)

新しいアカウントの作成方法

既存のログイン環境で以下を実行する:
(ここでは設定する新しいユーザー名をNEWUSERとする)

sudo su - useradd -m NEWUSER passwd NEWUSER usermod -G sudo NEWUSER ここで、いったんログアウトして NEWUSERでログインする。 # デフォルトのshellがbashでないので # bashに設定し直す # 現在のshell echo $SHELL /usr/bin/sh # bashのパスの確認 which bash /usr/bin/bash # shellのパスを上で確認したパスにする chsh -s /usr/bin/bash # 設定を有効にするため、いったんログアウトして、再ログインする 必要があれば既存の.bashrcの内容を 新しいログインの.bashrcにコピーする https://beta-notes.way-nifty.com/blog/2021/02/post-2b331d.html 「arduinoフレームワーク用platformio.ini集」 の「PlatformIOのインストール」、「udev登録」を参照して platformioを(再)インストールする。

参照情報

terminal関連:
Bootterm – a developer-friendly serial terminal program

ディレクトリ関連:
「/bin」「/usr/bin」「/usr/local/bin」ディレクトリの使い分け
Ubuntu でホームディレクトリ内のディレクトリ名を英語表記に

platformio関連:
arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

Arduino-IDE関連:
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

以上

続きを読む "platformioのために新しいユーザーを設定する"

| | コメント (0)

2022年1月 9日 (日)

MAKER_PI_RP2040でI2Cを使う(Arduino編)

2022/1/9
初版

MAKER_PI_RP2040_I2C

MAKER_PI_RP2040_I2C

概要

MAKER_PI_RP2040でI2Cを使う。
MAKER_PI_RP2040「MAKER_PI_RP2040」はCircuitPythonがプリインストールされている。Arduinoとして使用する際、通常wire,wire1の2つが使用できるが本ボードでは複数のI2Cが使用可能なgroveソケットを持っているので、どれを使用したら良いかが不明である。
そこでArduino-IDEとしてはpico公式版ではなく非公式earlephilhower/arduino picoでを使用する。この版は、I2Cのピンの割当関数があるので、それを使って使用するピンを指定できる。

留意点:
/dev/ttyACM0が見えている場合、USB-Serial経由の制御で自動的に書き込みモードになるので、特に操作はいらない。/dev/ttyACM0が見えていないときは、自動での書き込みモードができないので、手動で、[BOOT],[RST]ボタンを使って書き込みモードにすること。

I2C_Scanner

まずは、以下のスケッチで、I2Cの動作確認と接続しているI2Cデバイスのアドレスを確認する。
GROVE#4にI2Cデバイス(またはI2C-HUB経由)を接続する。

Arduino公式サイトにあったものにピン割当を追加しただけだが、以下にそのまま掲げる:
I2C_Scanner.ino

// -------------------------------------- // i2c_scanner // // Version 1 // This program (or code that looks like it) // can be found in many places. // For example on the Arduino.cc forum. // The original author is not know. // Version 2, Juni 2012, Using Arduino 1.0.1 // Adapted to be as simple as possible by Arduino.cc user Krodal // Version 3, Feb 26 2013 // V3 by louarnold // Version 4, March 3, 2013, Using Arduino 1.0.3 // by Arduino.cc user Krodal. // Changes by louarnold removed. // Scanning addresses changed from 0...127 to 1...119, // according to the i2c scanner by Nick Gammon // https://www.gammon.com.au/forum/?id=10896 // Version 5, March 28, 2013 // As version 4, but address scans now to 127. // A sensor seems to use address 120. // Version 6, November 27, 2015. // Added waiting for the Leonardo serial communication. // // // This sketch tests the standard 7-bit addresses // Devices with higher bit address might not be seen properly. // #include <Wire.h> void setup() { // GROVE#4 for I2C#0 Wire.setSDA(16); Wire.setSCL(17); //Wire.begin(); Wire.begin(); Serial.begin(9600); while (!Serial); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknown error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for next scan }

シリアル出力例:

I2C Scanner Scanning... I2C device found at address 0x3D ! I2C device found at address 0x76 ! done Scanning... I2C device found at address 0x3D ! I2C device found at address 0x76 ! done

BMP280のスケッチ

M5Stack用の「M5Stack用大気圧センサーユニット【M5STACK-U090】」をGROVE#4に接続して使用する。
本ユニットはBMP280を使用しており、BMP280のAdafruitのライブラリが使用できる。 以下は提供されているサンプルにピン割当、デバイスアドレスの変更をしたものである。

bmp280_sensortest_MAKER.ino

/*************************************************************************** This is a library for the BMP280 humidity, temperature & pressure sensor This example shows how to take Sensor Events instead of direct readings Designed specifically to work with the Adafruit BMP280 Breakout ----> http://www.adafruit.com/products/2651 These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried & Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution ***************************************************************************/ #include <Wire.h> #include <SPI.h> #include <Adafruit_BMP280.h> Adafruit_BMP280 bmp; // use I2C interface Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor(); Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor(); void setup() { Serial.begin(9600); while ( !Serial ) delay(100); // wait for native usb Serial.println(F("BMP280 Sensor event test")); // GROVE#4 for I2C#0 Wire.setSDA(16); Wire.setSCL(17); Wire.begin(); unsigned status; //status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID); status = bmp.begin(0x76); // for BPS UNIT of M5Stack if (!status) { Serial.println(F("Could not find a valid BMP280 sensor, check wiring or " "try a different address!")); Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16); Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); Serial.print(" ID of 0x60 represents a BME 280.\n"); Serial.print(" ID of 0x61 represents a BME 680.\n"); while (1) delay(10); } /* Default settings from datasheet. */ bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ Adafruit_BMP280::FILTER_X16, /* Filtering. */ Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ bmp_temp->printSensorDetails(); } void loop() { sensors_event_t temp_event, pressure_event; bmp_temp->getEvent(&temp_event); bmp_pressure->getEvent(&pressure_event); Serial.print(F("Temperature = ")); Serial.print(temp_event.temperature); Serial.println(" *C"); Serial.print(F("Pressure = ")); Serial.print(pressure_event.pressure); Serial.println(" hPa"); Serial.println(); delay(2000); }

シリアル出力例:

BMP280 Sensor event test ------------------------------------ Sensor: BMP280 Type: Ambient Temp (C) Driver Ver: 1 Unique ID: 280 Min Value: -40.00 Max Value: 85.00 Resolution: 0.01 ------------------------------------ Temperature = 19.14 *C Pressure = 1012.88 hPa Temperature = 19.15 *C Pressure = 1012.81 hPa Temperature = 19.15 *C Pressure = 1012.83 hPa

Qwiic_OLEDのスケッチ

Qwiic - 小型OLEDモジュールをQwiic->Grove変換ケーブル経由でGROVE#4に接続する。
(なぜかピン割当を追加せず)提供されたスケッチがそのまま動作したが以下に挙げる:
(ちなみに正式版Arduinoでは動作しなかった)

Example10_MultiDemo_v13.ino

/* SFE_MicroOLED Library Demo Paul Clark @ SparkFun Electronics Original Creation Date: December 11th, 2020 This sketch uses the MicroOLED library to show all the functionality built into the library using the begin function defined in version v1.3 of the library - which allows different TwoWire ports and custom I2C addresses to be used. If you are using the standard Micro OLED display, its I2C address will be 0x3D or 0x3C depending on how you have the D/C or ADDR jumper configured. Hardware Connections: This example assumes you are using Qwiic. See the SPI examples for a detailed breakdown of connection info. Want to support open source hardware? Buy a board from SparkFun! https://www.sparkfun.com/products/13003 https://www.sparkfun.com/products/14532 This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! Distributed as-is; no warranty is given. */ #include <Wire.h> #include <SFE_MicroOLED.h> //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED #define PIN_RESET 9 /* // This is the old way of instantiating oled. You can still do it this way if you want to. #define DC_JUMPER 1 MicroOLED oled(PIN_RESET, DC_JUMPER); // I2C declaration */ // From version v1.3, we can also instantiate oled like this (but only for I2C) MicroOLED oled(PIN_RESET); // The TwoWire I2C port is passed to .begin instead void setup() { delay(100); Wire.begin(); // <-- Change this to (e.g.) Qwiic.begin(); as required //Wire.setClock(400000); // Uncomment this line to increase the I2C bus speed to 400kHz /* // This is the old way of initializing the OLED. // You can still do it this way if you want to - but only // if you instantiated oled using: MicroOLED oled(PIN_RESET, DC_JUMPER) oled.begin(); // Initialize the OLED */ // This is the new way of initializing the OLED. // We can pass a different I2C address and TwoWire port oled.begin(0x3D, Wire); // Initialize the OLED /* // This is the new way of initializing the OLED. // We can pass a different I2C address and TwoWire port oled.begin(0x3C, Qwiic); // Initialize the OLED */ oled.clear(ALL); // Clear the display's internal memory oled.display(); // Display what's in the buffer (splashscreen) delay(1000); // Delay 1000 ms oled.clear(PAGE); // Clear the buffer. randomSeed(analogRead(A0) + analogRead(A1)); } void pixelExample() { printTitle("Pixels", 1); for (int i = 0; i < 512; i++) { oled.pixel(random(oled.getLCDWidth()), random(oled.getLCDHeight())); oled.display(); } } void lineExample() { int middleX = oled.getLCDWidth() / 2; int middleY = oled.getLCDHeight() / 2; int xEnd, yEnd; int lineWidth = min(middleX, middleY); printTitle("Lines!", 1); for (int i = 0; i < 3; i++) { for (int deg = 0; deg < 360; deg += 15) { xEnd = lineWidth * cos(deg * PI / 180.0); yEnd = lineWidth * sin(deg * PI / 180.0); oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd); oled.display(); delay(10); } for (int deg = 0; deg < 360; deg += 15) { xEnd = lineWidth * cos(deg * PI / 180.0); yEnd = lineWidth * sin(deg * PI / 180.0); oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd, BLACK, NORM); oled.display(); delay(10); } } } void shapeExample() { printTitle("Shapes!", 0); // Silly pong demo. It takes a lot of work to fake pong... int paddleW = 3; // Paddle width int paddleH = 15; // Paddle height // Paddle 0 (left) position coordinates int paddle0_Y = (oled.getLCDHeight() / 2) - (paddleH / 2); int paddle0_X = 2; // Paddle 1 (right) position coordinates int paddle1_Y = (oled.getLCDHeight() / 2) - (paddleH / 2); int paddle1_X = oled.getLCDWidth() - 3 - paddleW; int ball_rad = 2; // Ball radius // Ball position coordinates int ball_X = paddle0_X + paddleW + ball_rad; int ball_Y = random(1 + ball_rad, oled.getLCDHeight() - ball_rad); //paddle0_Y + ball_rad; int ballVelocityX = 1; // Ball left/right velocity int ballVelocityY = 1; // Ball up/down velocity int paddle0Velocity = -1; // Paddle 0 velocity int paddle1Velocity = 1; // Paddle 1 velocity //while(ball_X >= paddle0_X + paddleW - 1) while ((ball_X - ball_rad > 1) && (ball_X + ball_rad < oled.getLCDWidth() - 2)) { // Increment ball's position ball_X += ballVelocityX; ball_Y += ballVelocityY; // Check if the ball is colliding with the left paddle if (ball_X - ball_rad < paddle0_X + paddleW) { // Check if ball is within paddle's height if ((ball_Y > paddle0_Y) && (ball_Y < paddle0_Y + paddleH)) { ball_X++; // Move ball over one to the right ballVelocityX = -ballVelocityX; // Change velocity } } // Check if the ball hit the right paddle if (ball_X + ball_rad > paddle1_X) { // Check if ball is within paddle's height if ((ball_Y > paddle1_Y) && (ball_Y < paddle1_Y + paddleH)) { ball_X--; // Move ball over one to the left ballVelocityX = -ballVelocityX; // change velocity } } // Check if the ball hit the top or bottom if ((ball_Y <= ball_rad) || (ball_Y >= (oled.getLCDHeight() - ball_rad - 1))) { // Change up/down velocity direction ballVelocityY = -ballVelocityY; } // Move the paddles up and down paddle0_Y += paddle0Velocity; paddle1_Y += paddle1Velocity; // Change paddle 0's direction if it hit top/bottom if ((paddle0_Y <= 1) || (paddle0_Y > oled.getLCDHeight() - 2 - paddleH)) { paddle0Velocity = -paddle0Velocity; } // Change paddle 1's direction if it hit top/bottom if ((paddle1_Y <= 1) || (paddle1_Y > oled.getLCDHeight() - 2 - paddleH)) { paddle1Velocity = -paddle1Velocity; } // Draw the Pong Field oled.clear(PAGE); // Clear the page // Draw an outline of the screen: oled.rect(0, 0, oled.getLCDWidth() - 1, oled.getLCDHeight()); // Draw the center line oled.rectFill(oled.getLCDWidth() / 2 - 1, 0, 2, oled.getLCDHeight()); // Draw the Paddles: oled.rectFill(paddle0_X, paddle0_Y, paddleW, paddleH); oled.rectFill(paddle1_X, paddle1_Y, paddleW, paddleH); // Draw the ball: oled.circle(ball_X, ball_Y, ball_rad); // Actually draw everything on the screen: oled.display(); delay(25); // Delay for visibility } delay(1000); } void textExamples() { printTitle("Text!", 1); // Demonstrate font 0. 5x8 font oled.clear(PAGE); // Clear the screen oled.setFontType(0); // Set font to type 0 oled.setCursor(0, 0); // Set cursor to top-left // There are 255 possible characters in the font 0 type. // Lets run through all of them and print them out! for (int i = 0; i <= 255; i++) { // You can write byte values and they'll be mapped to // their ASCII equivalent character. oled.write(i); // Write a byte out as a character oled.display(); // Draw on the screen delay(10); // Wait 10ms // We can only display 60 font 0 characters at a time. // Every 60 characters, pause for a moment. Then clear // the page and start over. if ((i % 60 == 0) && (i != 0)) { delay(500); // Delay 500 ms oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left } } delay(500); // Wait 500ms before next example // Demonstrate font 1. 8x16. Let's use the print function // to display every character defined in this font. oled.setFontType(1); // Set font to type 1 oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left // Print can be used to print a string to the screen: oled.print(" !\"#$%&'()*+,-./01234"); oled.display(); // Refresh the display delay(1000); // Delay a second and repeat oled.clear(PAGE); oled.setCursor(0, 0); oled.print("56789:;<=>?@ABCDEFGHI"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("JKLMNOPQRSTUVWXYZ[\\]^"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("_`abcdefghijklmnopqrs"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("tuvwxyz{|}~"); oled.display(); delay(1000); // Demonstrate font 2. 10x16. Only numbers and '.' are defined. // This font looks like 7-segment displays. // Lets use this big-ish font to display readings from the // analog pins. for (int i = 0; i < 25; i++) { oled.clear(PAGE); // Clear the display oled.setCursor(0, 0); // Set cursor to top-left oled.setFontType(0); // Smallest font oled.print("A0: "); // Print "A0" oled.setFontType(2); // 7-segment font oled.print(analogRead(A0)); // Print a0 reading oled.setCursor(0, 16); // Set cursor to top-middle-left oled.setFontType(0); // Repeat oled.print("A1: "); oled.setFontType(2); oled.print(analogRead(A1)); oled.setCursor(0, 32); oled.setFontType(0); oled.print("A2: "); oled.setFontType(2); oled.print(analogRead(A2)); oled.display(); delay(100); } // Demonstrate font 3. 12x48. Stopwatch demo. oled.setFontType(3); // Use the biggest font int ms = 0; int s = 0; while (s <= 5) { oled.clear(PAGE); // Clear the display oled.setCursor(0, 0); // Set cursor to top-left if (s < 10) oled.print("00"); // Print "00" if s is 1 digit else if (s < 100) oled.print("0"); // Print "0" if s is 2 digits oled.print(s); // Print s's value oled.print(":"); // Print ":" oled.print(ms); // Print ms value oled.display(); // Draw on the screen ms++; // Increment ms if (ms >= 10) // If ms is >= 10 { ms = 0; // Set ms back to 0 s++; // and increment s } } } void loop() { //pixelExample(); // Run the pixel example function lineExample(); // Then the line example function shapeExample(); // Then the shape example textExamples(); // Finally the text example } // Center and print a small title // This function is quick and dirty. Only works for titles one // line long. void printTitle(String title, int font) { int middleX = oled.getLCDWidth() / 2; int middleY = oled.getLCDHeight() / 2; oled.clear(PAGE); oled.setFontType(font); // Try to set the cursor in the middle of the screen oled.setCursor(middleX - (oled.getFontWidth() * (title.length() / 2)), middleY - (oled.getFontHeight() / 2)); // Print the title: oled.print(title); oled.display(); delay(1500); oled.clear(PAGE); }

Grove_4Digit_displayのスケッチ(おまけ)

I2Cデバイスでないが Seeed-Studio/Grove_4Digit_DisplayをGROVE#6に接続して動作したスケッチを挙げる。
(CLKとDIOに修正を加えた)

NumberFlow_MAKER.ino

/* * TM1637.cpp * A library for the 4 digit display * * Copyright (c) 2012 seeed technology inc. * Website : www.seeed.cc * Author : Frankie.Chu * Create Time: 9 April,2012 * Change Log : * * The MIT License (MIT) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "TM1637.h" /* #define CLK 2//pins definitions for TM1637 and can be changed to other ports #define DIO 3 */ // for MAKER PI RP2040 #define CLK 27 //pins definitions for TM1637 and can be changed to other ports #define DIO 26 TM1637 tm1637(CLK,DIO); void setup() { tm1637.init(); tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; } void loop() { int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F int8_t ListDisp[4]; unsigned char i = 0; unsigned char count = 0; delay(150); while(1) { i = count; count ++; if(count == sizeof(NumTab)) count = 0; for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++) { ListDisp[BitSelect] = NumTab[i]; i ++; if(i == sizeof(NumTab)) i = 0; } tm1637.display(0,ListDisp[0]); tm1637.display(1,ListDisp[1]); tm1637.display(2,ListDisp[2]); tm1637.display(3,ListDisp[3]); delay(1000); //(300); } }

platformio.ini

I2Cを使用しているときは、現状、本件でplaatformioは使用できないが、
参考のためにplatformio.iniを挙げる:

MAKER_PI_RP2040用:
platformio.ini

[env:pico] platform = https://github.com/platformio/platform-raspberrypi.git framework = arduino board = pico upload_port = /dev/ttyACM0 monitor_port = /dev/ttyACM0 ; directory for usb-over-serial monitor_speed = 115200 lib_deps = seeed-studio/Grove 4-Digit Display@^1.0.0

参考情報

terminal関連:
Bootterm – a developer-friendly serial terminal program

MAKER PI RP2040関連:
MAKER PI RP2040 - Datasheet Rev 1.2 January 2022
Maker Pi RP2040 Schematic.pdf

platformio関連:

arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

Arduino-IDE関連:
Raspberry Pi PicoでI2C/SPI通信
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

以上

続きを読む "MAKER_PI_RP2040でI2Cを使う(Arduino編)"

| | コメント (0)

2021年12月12日 (日)

M5Stamp-PICO Arduino Install

2021/12/12
初版

M5Stamp-PICO Arduino Install

M5Stamp-PICO Arduino Install

概要

Arduino-IDEで「M5Stamp Pico Mate」を動かす。
ただし、本ボード単体では書き込みができないので、USBシリアルボードを用意する必要がある。キットとして書き込みボード付きの「M5Stamp Pico DIY Kit」ものもあるので、それを購入するのが一番簡単である。
書き込みのピン配列も合わせてあるので、余計なジャンパー無しに使用できる。ただし、価格的に割高な感がある。
なお、Arduino-IDEの最新版がインストール済みのものとする。
また、platformioでの使用する際のplatformio.iniについても記載する。

linuxのArduino-IDEのインストールについては以下を参照のこと。
Install the Arduino Software (IDE) on Linux

本記事は、linux版Arduino-IDEについて記述したものであるが、 ほとんど、そのままwindows版でも適応可能である。

USB serial ドライバーの設定

windows10については特別に何かをインストールする必要はなかった。
linuxの場合、udevの設定が必要になるが、platformioでの設定を以下のように流用する。

udev登録 以下を実行して、udevのrulesを登録する: curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules sudo udevadm control --reload-rules sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER

ボード情報(*.json)のインストール

Arduino-IDEを起動して以下を実行する:
1.[ファイル]/[環境設定]を選択する
2.画面の「追加のボードマネージャーのURL」に以下を入力(追加)する

https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json

3.入力後、[OK]をクリックする
4.[ツール]/[ボード]/[ボードマネージャー]を選択する
5.検索欄に「M5」と入力する
6.検索結果から「M5STACK」を選び、[インストール]をクリックする
7.インストール後、[閉じる]をクリックする

8.[ツール]/[ボード]/[M5Stack Arduino]/[STAMP-PICO]を選択する

以上で、ボードとして[STAMP-PICO]が選択されたことになる。

なお、シリアルポートは通常「/dev/ttyACM0」になる。

注意:
書き込みボード(ESP32-DOWNLOADER)は、接続用のピンをSTAMP-PICOボードに単純に差し込んだ状態でも書き込みが可能だが、
接触が不安定になるので、手で押さえるなり、接触が安定する工夫が必要となる。

以下、実際に動かしたスケッチを挙げる:

ASCIITablePico.ino

/* ASCII table Prints out byte values in all possible formats: * as raw binary values * as ASCII-encoded decimal, hex, octal, and binary values For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII The circuit: No external hardware needed. created 2006 by Nicholas Zambetti modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. <http://www.zambetti.com> */ void setup() { //Initialize serial and wait for port to open: //Serial.begin(9600); Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); } // first visible ASCIIcharacter '!' is number 33: int thisByte = 33; // you can also write ASCII characters in single quotes. // for example. '!' is the same as 33, so you could also use this: //int thisByte = '!'; void loop() { // prints value unaltered, i.e. the raw binary version of the // byte. The serial monitor interprets all bytes as // ASCII, so 33, the first number, will show up as '!' Serial.write(thisByte); Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. //this also works if you uncomment it: // Serial.print(thisByte, DEC); Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): Serial.print(thisByte, HEX); Serial.print(", oct: "); // prints value as string in octal (base 8); Serial.print(thisByte, OCT); Serial.print(", bin: "); // prints value as string in binary (base 2) // also prints ending line break: Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: if (thisByte == 126) { // you could also use if (thisByte == '~') { thisByte = 33-1; Serial.println("--------------------------------------------------"); //Serial.println("--------------------------------------------------"); Serial.println(""); delay(500); /* // This loop loops forever and does nothing while (true) { continue; } */ } // go on to the next character thisByte++; }

Arduinoの標準サンプルをserialのbpsの変更とリセット無しに繰り返すようにしたものになる。

platformioの設定

plaformio.ini は、以下を使用する:

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:esp32dev] platform = espressif32 #board = esp32dev board = m5stick-c framework = arduino //upload_port = /dev/ttyUSB0 upload_port = /dev/ttyACM0 monitor_speed = 115200 lib_deps = # use M5Atom lib 3113 # use "FastLED" 126 lib_ldf_mode = deep+

sample code for platfomio

b3NTP.ino

// select board ////#define WIO_TERMINAL ////#define ESP8266 ////#define ESP32 ////#define M5ATOM //------------------ // NTP Client for Wio-Terminal/ESP8266/ESP32 #ifdef M5ATOM #include "M5Atom.h" #define ESP32 #endif #ifdef WIO_TERMAL //#include <AtWiFi.h> #include <rpcWiFi.h> #endif #ifdef ESP8266 #include <ESP8266WiFi.h> #endif #ifdef ESP32 #include <WiFi.h> #endif #include <time.h> #define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password" void setup() { Serial.begin(115200); delay(100); Serial.print("\r\n\nReset:\r\n"); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while(WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(500); } Serial.println(); Serial.printf("Connected, IP address: "); Serial.println(WiFi.localIP()); configTzTime("JST-9", "ntp.nict.jp", "ntp.jst.mfeed.ad.jp"); // 2.7.0以降, esp32コンパチ } void loop() { time_t t; struct tm *tm; static const char *wd[7] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat"}; t = time(NULL); tm = localtime(&t); /***** Serial.printf("ESP8266/Arduino ver%s : %04d/%02d/%02d(%s) %02d:%02d:%02d\n", __STR(ARDUINO_ESP8266_GIT_DESC), tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); ****/ Serial.printf("Arduino NTP: %04d/%02d/%02d(%s) %02d:%02d:%02d\r\n", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); delay(1000); }

以下はwifi環境に応じて変更すること:

#define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password"

本ソースは、WIO_TERMINAL、ESP8266、ESP32、M5ATOMで共通になっており、platformio.iniの内容でターゲットを切り替えることができる。

platformioのビルドと書き込み:

# ライブラリのインストール(1回目のみ) pio run -t clean # ボードをPCに接続する pio run -t upload

実行時のシリアル出力(/dev/ttyACM0):

........ Connected, IP address: 192.168.1.15 Arduino NTP: 1970/01/01(Thr) 09:00:04 Arduino NTP: 1970/01/01(Thr) 09:00:05 Arduino NTP: 1970/01/01(Thr) 09:00:06 Arduino NTP: 1970/01/01(Thr) 09:00:07 Arduino NTP: 1970/01/01(Thr) 09:00:08 Arduino NTP: 2021/12/11(Sat) 16:55:59 ← ここでNTPによって時刻が同期している Arduino NTP: 2021/12/11(Sat) 16:56:00 Arduino NTP: 2021/12/11(Sat) 16:56:01

sample code #2 for platformio

main.ino

#include <Adafruit_NeoPixel.h> #define BUTTON 39 // for STAMP-PICO #define LED 27 // for STAMP-PICO #define NUMPIXELS 1 Adafruit_NeoPixel pixels(NUMPIXELS, LED, NEO_GRB + NEO_KHZ800); int lastState = HIGH; int currentState; int buttonCount = 1; void setup() { Serial.begin(115200); pixels.begin(); pinMode(BUTTON, INPUT_PULLUP); } int high = 255; int mid = 128; int low = 0; void setLed() { pixels.clear(); switch (buttonCount) { case 1: pixels.setPixelColor(0, pixels.Color(high, low, low)); break; case 2: pixels.setPixelColor(0, pixels.Color(high, mid, mid)); break; case 3: pixels.setPixelColor(0, pixels.Color(low, high, low)); break; case 4: pixels.setPixelColor(0, pixels.Color(mid, high, mid)); break; case 5: pixels.setPixelColor(0, pixels.Color(low, low, high)); break; case 6: pixels.setPixelColor(0, pixels.Color(mid, mid, high)); break; default: break; } pixels.show(); } void loop() { currentState = digitalRead(BUTTON); if(lastState == LOW && currentState == HIGH) { Serial.println("Button Pressed!"); buttonCount++; if (buttonCount > 6) { buttonCount = 1; } setLed(); } lastState = currentState; }

本サンプルは「This is an example PlatformIO project for M5Stamp C3」のものをSTAMP-PICO用に変更したものになる。
動作としては、ボタンを押すたびにLEDの色が変化する。 またボタンを押すたびに「Button Pressed!」がシリアル出力される。

参考情報

M5Stamp-Pico docs:
M5STAMP-PICO-DIY-KIT
STAMP-PICO Arduino Library

M5Stamp-Pico関連:
M5Stack M5Stamp Picoを買ってみた

Arduino-IDE関連:
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

platformio関連:
arduinoフレームワーク用platformio.ini集
This is an example PlatformIO project for M5Stamp C3

その他:
スルーホール用テストワイヤ TT-200 (10本入)

以上

続きを読む "M5Stamp-PICO Arduino Install"

| | コメント (0)

M5Stamp-C3 Arduino Install

2021/12/11
初版

M5Stamp-C3 Arduino Install

M5Stamp-C3 Arduino Install

概要

Arduino-IDEで「M5Stamp C3 Mate」を動かす。本ボードは簡単にいうと従来のESP32のCPUをRISC-V(32bits)CPUに置き換えたものになる。
ホスト環境は、ubuntu20.04とする。
なお、Arduino-IDEの最新版がインストール済みのものとする。 また、platformioでの使用する際のplatformio.iniについても記載する。

linuxのArduino-IDEのインストールについては以下を参照のこと。
Install the Arduino Software (IDE) on Linux

本記事は、linux版Arduino-IDEについて記述したものであるが、 ほとんど、そのままwindows版でも適応可能である。

USB serial ドライバーの設定

windows10については特別に何かをインストールする必要はなかった。 linuxの場合、udevの設定が必要になるが、platformioでの設定を以下のように流用する。

udev登録 以下を実行して、udevのrulesを登録する: curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules sudo udevadm control --reload-rules sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER

ボード情報(*.json)のインストール

Arduino-IDEを起動して以下を実行する:
1.[ファイル]/[環境設定]を選択する
2.画面の「追加のボードマネージャーのURL」に以下を入力(追加)する

https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json

3.入力後、[OK]をクリックする
4.[ツール]/[ボード]/[ボードマネージャー]を選択する
5.検索欄に「M5」と入力する
6.検索結果から「M5STACK」を選び、[インストール]をクリックする
7.インストール後、[閉じる]をクリックする

8.[ツール]/[ボード]/[M5Stack Arduino]/[STAMP-C3]を選択する

以上で、ボードとして[STAMP-C3]が選択されたことになる。

# ASCIITable.inoのようにUSB serialを動かす場合 # ツール設定を以下にする: USB CDC On Boot: "Disable"

なお、シリアルポートは通常「/dev/ttyACM0」になる。

以下、実際に動かしたスケッチを挙げる:

ASCIITableM.ino

/* ASCII table Prints out byte values in all possible formats: * as raw binary values * as ASCII-encoded decimal, hex, octal, and binary values For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII The circuit: No external hardware needed. created 2006 by Nicholas Zambetti modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. <http://www.zambetti.com> */ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); // while (!Serial) { // ; // wait for serial port to connect. Needed for Leonardo only // } // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map"); } // first visible ASCIIcharacter '!' is number 33: int thisByte = 33; // you can also write ASCII characters in single quotes. // for example. '!' is the same as 33, so you could also use this: //int thisByte = '!'; void loop() { // prints value unaltered, i.e. the raw binary version of the // byte. The serial monitor interprets all bytes as // ASCII, so 33, the first number, will show up as '!' Serial.write(thisByte); Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. //this also works if you uncomment it: // Serial.print(thisByte, DEC); Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): Serial.print(thisByte, HEX); Serial.print(", oct: "); // prints value as string in octal (base 8); Serial.print(thisByte, OCT); Serial.print(", bin: "); // prints value as string in binary (base 2) // also prints ending line break: Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: if(thisByte == 126) { // you could also use if (thisByte == '~') { // This loop loops forever and does nothing while(true) { continue; } } // go on to the next character thisByte++; }

Arduinoの標準サンプルでserialのbpsのみを変更したものになる。

platformioの設定

platformio.iniの設定だけでは自動的にインストールできないものが あるので以下の手順で、予めインストールしておく。

# userの top directory mkdir tools cd tools # ダウンロード wget https://github.com/espressif/crosstool-NG/releases/download/esp-2021r2/riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz # 解凍 tar -xzvf riscv32-esp-elf-gcc8_4_0-esp-2021r2-linux-amd64.tar.gz # package.jsonのコピー cd ~/tools/riscv32-esp-elf cp ~/.platformio/packages/toolchain-riscv-esp/package.json .

plaformio.ini は、以下を使用する:

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:esp32c3] platform = espressif32 platform_packages = toolchain-riscv-esp@file:///home/<USER>/tools/riscv32-esp-elf framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#master platformio/tool-esptoolpy framework = arduino board = esp32dev board_build.mcu = esp32c3 board_build.partitions = huge_app.csv board_build.variant = esp32c3 board_build.f_cpu = 160000000L board_build.f_flash = 80000000L board_build.flash_mode = dio board_build.arduino.ldscript = esp32c3_out.ld build_unflags = -DARDUINO_ESP32_DEV -DARDUINO_VARIANT="esp32" build_flags = -DARDUINO_ESP32C3_DEV -DARDUINO_VARIANT="esp32c3" lib_deps = adafruit/Adafruit NeoPixel@^1.10.0 monitor_speed = 115200 monitor_filters = time

上のplatformio.iniは「This is an example PlatformIO project for M5Stamp C3」のものをベースにして、そのままでは動作しないので若干変更したものになる。 「<USER>」の部分は、自分の環境に合わせて変更すること。

sample code for platfomio

b3NTP.ino

// select board ////#define WIO_TERMINAL ////#define ESP8266 ////#define ESP32 ////#define M5ATOM //------------------ // NTP Client for Wio-Terminal/ESP8266/ESP32 #ifdef M5ATOM #include "M5Atom.h" #define ESP32 #endif #ifdef WIO_TERMAL //#include <AtWiFi.h> #include <rpcWiFi.h> #endif #ifdef ESP8266 #include <ESP8266WiFi.h> #endif #ifdef ESP32 #include <WiFi.h> #endif #include <time.h> #define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password" void setup() { Serial.begin(115200); delay(100); Serial.print("\r\n\nReset:\r\n"); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while(WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(500); } Serial.println(); Serial.printf("Connected, IP address: "); Serial.println(WiFi.localIP()); configTzTime("JST-9", "ntp.nict.jp", "ntp.jst.mfeed.ad.jp"); // 2.7.0以降, esp32コンパチ } void loop() { time_t t; struct tm *tm; static const char *wd[7] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat"}; t = time(NULL); tm = localtime(&t); /***** Serial.printf("ESP8266/Arduino ver%s : %04d/%02d/%02d(%s) %02d:%02d:%02d\n", __STR(ARDUINO_ESP8266_GIT_DESC), tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); ****/ Serial.printf("Arduino NTP: %04d/%02d/%02d(%s) %02d:%02d:%02d\r\n", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); delay(1000); }

以下はwifi環境に応じて変更すること:

#define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password"

本ソースは、WIO_TERMINAL、ESP8266、ESP32、M5ATOMで共通になっており、platformio.iniの内容でターゲットを切り替えることができる。

platformioのビルドと書き込み

# ライブラリのインストール(1回目のみ) pio run -t clean # ボードをPCに接続する pio run -t upload

実行時のシリアル出力(/dev/ttyACM0):

Build:Feb 7 2021 rst:0xf (BROWNOUT_RST),boot:0xc (SPI_FAST_FLASH_BOOT) SPIWP:0xee mode:DIO, clock div:1 load:0x3fcd6100,len:0x3f0 load:0x403ce000,len:0x6a8 load:0x403d0000,len:0x2398 SHA-256 comparison failed: Calculated: 071318b1de86cde7f1aec94a59e4cb69b9476060b25c8688588480d5e8f36d1c Expected: aeb43c2bf68a09f09f2b1d7c8bb79c7727cf0a2b827a76540c98a24fcafdd49a Attempting to boot anyway... entry 0x403ce000 Reset: ........ Connected, IP address: 192.168.1.15 Arduino NTP: 1970/01/01(Thr) 09:00:04 Arduino NTP: 1970/01/01(Thr) 09:00:05 Arduino NTP: 1970/01/01(Thr) 09:00:06 Arduino NTP: 1970/01/01(Thr) 09:00:07 Arduino NTP: 1970/01/01(Thr) 09:00:08 Arduino NTP: 2021/12/11(Sat) 16:55:59 ← ここでNTPによって時刻が同期している Arduino NTP: 2021/12/11(Sat) 16:56:00 Arduino NTP: 2021/12/11(Sat) 16:56:01

sample code #2 for platformio

main.ino

#include <Adafruit_NeoPixel.h> #define BUTTON 3 #define LED 2 #define NUMPIXELS 1 Adafruit_NeoPixel pixels(NUMPIXELS, LED, NEO_GRB + NEO_KHZ800); int lastState = HIGH; int currentState; int buttonCount = 1; void setup() { Serial.begin(115200); pixels.begin(); pinMode(BUTTON, INPUT_PULLUP); } int high = 255; int mid = 128; int low = 0; void setLed() { pixels.clear(); switch (buttonCount) { case 1: pixels.setPixelColor(0, pixels.Color(high, low, low)); break; case 2: pixels.setPixelColor(0, pixels.Color(high, mid, mid)); break; case 3: pixels.setPixelColor(0, pixels.Color(low, high, low)); break; case 4: pixels.setPixelColor(0, pixels.Color(mid, high, mid)); break; case 5: pixels.setPixelColor(0, pixels.Color(low, low, high)); break; case 6: pixels.setPixelColor(0, pixels.Color(mid, mid, high)); break; default: break; } pixels.show(); } void loop() { currentState = digitalRead(BUTTON); if(lastState == LOW && currentState == HIGH) { Serial.println("Button Pressed!"); buttonCount++; if (buttonCount > 6) { buttonCount = 1; } setLed(); } lastState = currentState; }

本サンプルは「This is an example PlatformIO project for M5Stamp C3」のものになる。
動作としては、ボタンを押すたびにLEDの色が変化する。 またボタンを押すたびに「Button Pressed!」がシリアル出力される。

参考情報

M5Stamp-C3 docs:
STAMP-C3
ESP32­C3 Technical Reference Manual
ESP32­C3 Series - Datasheet

Arduino-IDE関連:
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)
M5Stamp C3 Mateを試してみました【Arduino使用】

platformio関連:
arduinoフレームワーク用platformio.ini集
This is an example PlatformIO project for M5Stamp C3

その他: スルーホール用テストワイヤ TT-200 (10本入)

以上

続きを読む "M5Stamp-C3 Arduino Install"

| | コメント (0)

2021年5月19日 (水)

Arduino-CLIのインストール

2021/5/19
初版

Arduino-CLI Install

Arduino-CLI Install

概要

Arduino-CLIのインストール方法について記述する。
これはArduino-IDEを使わずにCLIだけでArduinoのcompile/uploadなどができる。
ホスト環境はubuntuを想定する。
なお、(インストールしたライブラリなどを流用する関係上)既にArduino-IDEがインストール済みであることが前提となる。

インストール手順

以下の手順を実行する:

cd ~ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh #出力例 Installing in /home/USER/bin ARCH=64bit OS=Linux Using curl as download tool TAG=0.18.3 CLI_DIST=arduino-cli_0.18.3_Linux_64bit.tar.gz Downloading https://downloads.arduino.cc/arduino-cli/arduino-cli_0.18.3_Linux_64bit.tar.gz arduino-cli not found. You might want to add /home/USER/bin to your $PATH arduino-cli alpha Version: 0.18.3 Commit: d710b642 Date: 2021-05-14T12:36:58Z installed successfully in /home/USER/bin # 実行パスを設定する(.bashrcにも登録する) export PATH=$PATH:$HOME/bin/

動作確認

mkdir ard_ws cd ard_ws/ # configファイルを初期化する arduino-cli config init #出力例 Config file written to: /home/USER/.arduino15/arduino-cli.yaml # arduino-cli.yamlファイルが$HOME/.arduino15/にできる # 新規のスケッチの作成 arduino-cli sketch new MyFirstSketch #出力例 Sketch created in: /home/USR/ard_ws/MyFirstSketch # 新規スケッチの内容の確認 cat MyFirstSketch/MyFirstSketch.ino void setup() { } void loop() { } # インストールされているボード・ライブラリの確認 arduino-cli board listall uno #出力 Board Name FQBN Arduino Uno arduino:avr:uno Arduino Uno WiFi arduino:avr:unowifi arduino-cli board listall xiao #出力 Board Name FQBN Seeeduino XIAO Seeeduino:samd:seeed_XIAO_m0 arduino-cli board listall wio #出力 Board Name FQBN Seeed Wio Link esp8266:esp8266:wiolink Seeeduino Wio GPS Board Seeeduino:samd:WioGPS Seeeduino Wio Terminal Seeeduino:samd:seeed_wio_terminal Seeeduino Wio lite MG126 Seeeduino:samd:Wio_Lite_MG126 arduino-cli board listall pico #出力 Board Name FQBN Adafruit Feather RP2040 (Picoprobe) rp2040:rp2040:adafruitfeatherpicoprobe Generic RP2040 (Picoprobe) rp2040:rp2040:genericpicoprobe Raspberry Pi Pico rp2040:rp2040:rpipico Raspberry Pi Pico arduino:mbed_rp2040:pico Raspberry Pi Pico (Picoprobe) rp2040:rp2040:rpipicopicoprobe #--------------------------------- # Install the core for your board arduino-cli core install Seeeduino:samd #出力 Platform Seeeduino:samd@1.8.1 already installed #Arduino-IDEでインストール済みなので「already installed」 arduino-cli core update-index #出力 Updating index: package_index.json downloaded Updating index: package_index.json.sig downloaded #---------------------------------- # 任意のスケッチに編集する gedit MyFirstSketch/MyFirstSketch.ino # Compile and upload the sketch #compile arduino-cli compile -b arduino:avr:uno MyFirstSketch #出力例 Sketch uses 932 bytes (2%) of program storage space. Maximum is 32256 bytes. Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes. #upload arduino-cli upload -p /dev/ttyUSB0 -b arduino:avr:uno MyFirstSketch #特に出力はないようだ

既存のスケッチのcompile/upload

既存のスケッチのcompile/uploadについては
以下のように行なう:

cd ~/Arduino # ディレクトリ内容の確認 ls ASCIITablePico ASCIITable_M5Atom BlinkPico MB_graphicstest libraries # ビルドしたいスケッチのディレクトリに入る cd ASCIITablePico # compile arduino-cli compile -b rp2040:rp2040:rpipico #出力例 Sketch uses 214480 bytes (10%) of program storage space. Maximum is 2093056 bytes. Global variables use 17064 bytes (6%) of dynamic memory, leaving 245080 bytes for local variables. Maximum is 262144 bytes. # upload arduino-cli upload -p /dev/ttyACM0 -b rp2040:rp2040:rpipico #出力例 Resetting /dev/ttyACM0 Converting to uf2, output size: 442880, start address: 0x2000 Flashing /media/USER/RPI-RP2 (RPI-RP2) Wrote 442880 bytes to /media/USER/RPI-RP2/NEW.UF2 #------------------------------ # 同じスケッチでboardを切り替える # ボード確認 arduino-cli board listall Atom #出力例 Board Name FQBN M5Stack-ATOM m5stack:esp32:m5stack-atom # compile arduino-cli compile -b m5stack:esp32:m5stack-atom #出力例 Sketch uses 213585 bytes (16%) of program storage space. Maximum is 1310720 bytes. Global variables use 15380 bytes (4%) of dynamic memory, leaving 312300 bytes for local variables. Maximum is 327680 bytes. # upload arduino-cli upload -p /dev/ttyUSB0 -b m5stack:esp32:m5stack-atom #出力例 esptool.py v3.0-dev Serial port /dev/ttyUSB0 Connecting..... Chip is ESP32-PICO-D4 (revision 1) Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None Crystal is 40MHz MAC: 50:02:91:90:04:e4 Uploading stub... Running stub... Stub running... Changing baud rate to 1500000 Changed. Configuring flash size... Auto-detected Flash size: 4MB Compressed 8192 bytes to 47... Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 15527.2 kbit/s)... Hash of data verified. Compressed 15856 bytes to 10276... Wrote 15856 bytes (10276 compressed) at 0x00001000 in 0.1 seconds (effective 1129.5 kbit/s)... Hash of data verified. Compressed 213696 bytes to 108970... Wrot  e 213696 bytes (108970 compressed) at 0x00010000 in 1.8 seconds (effective 960.5 kbit/s)... Hash of data verified. Compressed 3072 bytes to 128... Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 6202.5 kbit/s)... Hash of data verified. Leaving... Hard resetting via RTS pin...

3rd-partyのボード・ライブラリのインストール

例:

# install arduino-cli core update-index --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json #出力例 Updating index: package_index.json downloaded Updating index: package_index.json.sig downloaded Updating index: package_esp8266com_index.json downloaded # check arduino-cli core search esp8266 --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json #出力例 ID Version Name esp8266:esp8266 3.0.0 esp8266 # ボード・ライブラリ確認 arduino-cli board listall 8266 #出力例 Board Name FQBN 4D Systems gen4 IoD Range esp8266:esp8266:gen4iod Adafruit Feather HUZZAH ESP8266 esp8266:esp8266:huzzah Amperka WiFi Slot esp8266:esp8266:wifi_slot Arduino esp8266:esp8266:arduino-esp8266 DOIT ESP-Mx DevKit (ESP8285) esp8266:esp8266:espmxdevkit Digistump Oak esp8266:esp8266:oak ESPDuino (ESP-13 Module) esp8266:esp8266:espduino ESPectro Core esp8266:esp8266:espectro ESPino (ESP-12 Module) esp8266:esp8266:espino <省略>

参照情報

Arduino-CLI関連:
Arduino-CLI
getting-started
Arduino-cli: compile, upload and manage libraries, cores, and boards

Arduino-CLI内部関連:
Platform specification
Pre-Processing

以上

続きを読む "Arduino-CLIのインストール"

| | コメント (0)

2021年4月30日 (金)

LCDをmicrobit_arduinoで動かす

2021/5/3
スケッチをハードウェアSPIに切り替えた。

2021/4/30
初版

pio Microbit Arduino ST7735S

pio Microbit Arduino ST7735S

概要

以下のLCDをmicrobit_arduinoで動かす
1.8inch colorful display module for micro:bit, 160x128 (ST7735S)
(ホストはubuntu20.04を想定している)
platformioが既にインストールされている前提で説明する。

platformioのインストールについては以下などを参照のこと:
arduinoフレームワーク用platformio.ini集

platformio.ini

以下のplatformio.iniを利用する:

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [env:bbcmicrobit] platform = nordicnrf51 board = bbcmicrobit framework = arduino build_flags = -DMICROBIT -DNRF51_S110 monitor_speed = 115200 lib_ldf_mode = deep+ #upload_port = /media/USER/MICROBIT #upload_protocol = mbed upload_protocol = cmsis-dap lib_deps = https://github.com/adafruit/Adafruit_BusIO/archive/master.zip https://github.com/sparkfun/SparkFun_MAG3110_Breakout_Board_Arduino_Library/archive/master.zip https://cdn-learn.adafruit.com/assets/assets/000/046/217/original/MMA8653.zip https://github.com/stm32duino/LSM303AGR/archive/master.zip https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip # https://github.com/sandeepmistry/arduino-BLEPeripheral/archive/master.zip https://github.com/adafruit/Adafruit_Microbit/archive/master.zip # https://github.com/ht-deko/microbit_Screen/archive/master.zip # adafruit/Adafruit ST7735 and ST7789 Library @ ^1.7.2

graphicstest.ino

テスト用プログラムを以下のように作成する:
src/graphicstest.ino

// modified for Waveshare 1.8inch LCD for micro:bit, controler:ST7735S (2021/4/30) /************************************************************************** This is a library for several Adafruit displays based on ST77* drivers. Works with the Adafruit 1.8" TFT Breakout w/SD card ----> http://www.adafruit.com/products/358 The 1.8" TFT shield ----> https://www.adafruit.com/product/802 The 1.44" TFT breakout ----> https://www.adafruit.com/product/2088 The 1.14" TFT breakout ----> https://www.adafruit.com/product/4383 The 1.3" TFT breakout ----> https://www.adafruit.com/product/4313 The 1.54" TFT breakout ----> https://www.adafruit.com/product/3787 The 2.0" TFT breakout ----> https://www.adafruit.com/product/4311 as well as Adafruit raw 1.8" TFT display ----> http://www.adafruit.com/products/618 Check out the links above for our tutorials and wiring diagrams. These displays use SPI to communicate, 4 or 5 pins are required to interface (RST is optional). Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. MIT license, all text above must be included in any redistribution **************************************************************************/ #include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_ST7735.h> // Hardware-specific library for ST7735 #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789 #include <SPI.h> #ifndef MICROBIT #if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32 #define TFT_CS 14 #define TFT_RST 15 #define TFT_DC 32 #elif defined(ESP8266) #define TFT_CS 4 #define TFT_RST 16 #define TFT_DC 5 #else // For the breakout board, you can use any 2 or 3 pins. // These pins will also work for the 1.8" TFT shield. #define TFT_CS 10 #define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin #define TFT_DC 8 #endif // OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique // to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and // SCLK = pin 13. This is the fastest mode of operation and is required if // using the breakout board's microSD card. // For 1.44" and 1.8" TFT with ST7735 use: Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); // For 1.14", 1.3", 1.54", and 2.0" TFT with ST7789: //Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); // OPTION 2 lets you interface the display using ANY TWO or THREE PINS, // tradeoff being that performance is not as fast as hardware SPI above. //#define TFT_MOSI 11 // Data out //#define TFT_SCLK 13 // Clock out // For ST7735-based displays, we will use this call //Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); // OR for the ST7789-based displays, we will use this call //Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); #endif #ifdef MICROBIT // setup for Waveshare LCD #define TFT_CS 16 #define TFT_RST 8 #define TFT_DC 12 #define TFT_MOSI 15 // Data out #define TFT_SCLK 13 // Clock out #define BL_EN 1 // backlit enable //Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); // use Hardware SPI #endif float p = 3.1415926; void setup(void) { //pinMode(BL_EN, OUTPUT); //digitalWrite(BL_EN, HIGH); //Serial.begin(9600); Serial.begin(115200); Serial.print(F("Hello! ST77xx TFT Test")); #ifndef MICROBIT // Use this initializer if using a 1.8" TFT screen: tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab // OR use this initializer if using a 1.8" TFT screen with offset such as WaveShare: // tft.initR(INITR_GREENTAB); // Init ST7735S chip, green tab // OR use this initializer (uncomment) if using a 1.44" TFT: //tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab // OR use this initializer (uncomment) if using a 0.96" 160x80 TFT: //tft.initR(INITR_MINI160x80); // Init ST7735S mini display // OR use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT: //tft.init(240, 240); // Init ST7789 240x240 // OR use this initializer (uncomment) if using a 2.0" 320x240 TFT: //tft.init(240, 320); // Init ST7789 320x240 // OR use this initializer (uncomment) if using a 1.14" 240x135 TFT: //tft.init(135, 240); // Init ST7789 240x135 // SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here // Note that speed allowable depends on chip and quality of wiring, if you go too fast, you // may end up with a black screen some times, or all the time. //tft.setSPISpeed(40000000); #endif #ifdef MICROBIT tft.initR(INITR_GREENTAB); // Init ST7735S chip, green tab for WaveShare //tft.setRotation(1); // landscape (microbit board upside) tft.setRotation(2); // portrait (microbit board leftside) tft.setSPISpeed(40000000); #endif Serial.println(F("Initialized")); uint16_t time = millis(); tft.fillScreen(ST77XX_BLACK); time = millis() - time; Serial.println(time, DEC); delay(500); // large block of text tft.fillScreen(ST77XX_BLACK); testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE); delay(1000); // tft print function! tftPrintTest(); delay(4000); // a single pixel tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN); delay(500); // line draw test testlines(ST77XX_YELLOW); delay(500); // optimized lines testfastlines(ST77XX_RED, ST77XX_BLUE); delay(500); testdrawrects(ST77XX_GREEN); delay(500); testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA); delay(500); tft.fillScreen(ST77XX_BLACK); testfillcircles(10, ST77XX_BLUE); testdrawcircles(10, ST77XX_WHITE); delay(500); testroundrects(); delay(500); testtriangles(); delay(500); mediabuttons(); delay(500); Serial.println("done"); delay(1000); } void loop() { tft.invertDisplay(true); delay(500); tft.invertDisplay(false); delay(500); } void testlines(uint16_t color) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, 0, x, tft.height()-1, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, 0, tft.width()-1, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, 0, 0, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, tft.height()-1, x, 0, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, tft.height()-1, tft.width()-1, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color); delay(0); } } void testdrawtext(char *text, uint16_t color) { tft.setCursor(0, 0); tft.setTextColor(color); tft.setTextWrap(true); tft.print(text); } void testfastlines(uint16_t color1, uint16_t color2) { tft.fillScreen(ST77XX_BLACK); for (int16_t y=0; y < tft.height(); y+=5) { tft.drawFastHLine(0, y, tft.width(), color1); } for (int16_t x=0; x < tft.width(); x+=5) { tft.drawFastVLine(x, 0, tft.height(), color2); } } void testdrawrects(uint16_t color) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color); } } void testfillrects(uint16_t color1, uint16_t color2) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=tft.width()-1; x > 6; x-=6) { tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1); tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2); } } void testfillcircles(uint8_t radius, uint16_t color) { for (int16_t x=radius; x < tft.width(); x+=radius*2) { for (int16_t y=radius; y < tft.height(); y+=radius*2) { tft.fillCircle(x, y, radius, color); } } } void testdrawcircles(uint8_t radius, uint16_t color) { for (int16_t x=0; x < tft.width()+radius; x+=radius*2) { for (int16_t y=0; y < tft.height()+radius; y+=radius*2) { tft.drawCircle(x, y, radius, color); } } } void testtriangles() { tft.fillScreen(ST77XX_BLACK); uint16_t color = 0xF800; int t; int w = tft.width()/2; int x = tft.height()-1; int y = 0; int z = tft.width(); for(t = 0 ; t <= 15; t++) { tft.drawTriangle(w, y, y, x, z, x, color); x-=4; y+=4; z-=4; color+=100; } } void testroundrects() { tft.fillScreen(ST77XX_BLACK); uint16_t color = 100; int i; int t; for(t = 0 ; t <= 4; t+=1) { int x = 0; int y = 0; int w = tft.width()-2; int h = tft.height()-2; for(i = 0 ; i <= 16; i+=1) { tft.drawRoundRect(x, y, w, h, 5, color); x+=2; y+=3; w-=4; h-=6; color+=1100; } color+=100; } } void tftPrintTest() { tft.setTextWrap(false); tft.fillScreen(ST77XX_BLACK); tft.setCursor(0, 30); tft.setTextColor(ST77XX_RED); tft.setTextSize(1); tft.println("Hello World!"); tft.setTextColor(ST77XX_YELLOW); tft.setTextSize(2); tft.println("Hello World!"); tft.setTextColor(ST77XX_GREEN); tft.setTextSize(3); tft.println("Hello World!"); tft.setTextColor(ST77XX_BLUE); tft.setTextSize(4); tft.print(1234.567); delay(1500); tft.setCursor(0, 0); tft.fillScreen(ST77XX_BLACK); tft.setTextColor(ST77XX_WHITE); tft.setTextSize(0); tft.println("Hello World!"); tft.setTextSize(1); tft.setTextColor(ST77XX_GREEN); tft.print(p, 6); tft.println(" Want pi?"); tft.println(" "); tft.print(8675309, HEX); // print 8,675,309 out in HEX! tft.println(" Print HEX!"); tft.println(" "); tft.setTextColor(ST77XX_WHITE); tft.println("Sketch has been"); tft.println("running for: "); tft.setTextColor(ST77XX_MAGENTA); tft.print(millis() / 1000); tft.setTextColor(ST77XX_WHITE); tft.print(" seconds."); } void mediabuttons() { // play tft.fillScreen(ST77XX_BLACK); tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE); tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED); delay(500); // pause tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE); tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN); tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN); delay(500); // play color tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE); delay(50); // pause color tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED); tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED); // play color tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN); }

・「Adafruit ST7735 and ST7789 Library 」にあるExamplesを修正したもの。
・「#ifdef MICROBIT ... #endif」などで囲まれた部分が修正部分になる。

ビルド&書き込み

以下の手順でビルトと書き込みができる:

cd pico_proj # ツールなどのインストール(最初の1回のみ) pio run -t clean # ビルド&書き込み pio run -t upload # この時点で書き込みが完了する

書き込みが上手く行かない場合は、platformio.iniを以下のように変更すると正常に動作するようだ。
いったん、書き込みが正常動作した跡は、元に戻しても書き込みが正常動作するようだ。

#upload_port = /media/USER/MICROBIT #upload_protocol = mbed upload_protocol = cmsis-dap → upload_port = /media/USER/MICROBIT upload_protocol = mbed #upload_protocol = cmsis-dap

・USERは環境依存なので、実際の環境に合わせて変更する。

micro:bit-V2対応

以下のplatformio.iniでmicrobit-v2でビルド&書き込みができるが、正常動作しないようだ。
(原因不明)

platformio.ini

[env:bbcmicrobit_v2] platform = nordicnrf52 board = bbcmicrobit_v2 framework = arduino ;build_flags = -DMICROBIT_V2 build_flags = -DMICROBIT monitor_speed = 115200 lib_ldf_mode = deep+ #upload_port = /media/USER/MICROBIT #upload_protocol = mbed upload_protocol = cmsis-dap lib_deps = https://github.com/adafruit/Adafruit_BusIO/archive/master.zip https://github.com/sparkfun/SparkFun_MAG3110_Breakout_Board_Arduino_Library/archive/master.zip https://cdn-learn.adafruit.com/assets/assets/000/046/217/original/MMA8653.zip https://github.com/stm32duino/LSM303AGR/archive/master.zip https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip # adafruit/Adafruit ST7735 and ST7789 Library @ ^1.7.2

参考情報

LCD関連:
1.8inch LCD for micro:bit
1.8inch colorful display module for micro:bit, 160x128

Microbit_Arduino関連:
micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版)
micro:bitでmicrobit_screenライブラリを利用する(micro:bit-v2対応,linux版)
arduinoフレームワーク用platformio.ini集

platformio関連:
PlatformIO Core (CLI)
Arduino-IDEとPlatformioのコンパイラーの挙動の違いについて
arduinoフレームワーク用platformio.ini集
ubuntu20.04をインストールする

以上

続きを読む "LCDをmicrobit_arduinoで動かす"

| | コメント (0)

2021年4月26日 (月)

Display_Packをpico_arduinoで動かす

2021/4/28
LEDとSWの制御スケッチを追加した。

2021/4/25
初版

pio Pico Arduino Display Pack

pio Pico Arduino Display Pack

概要

以下のDisplay_Packをpico_arduinoで動かす
Pico Display Pack
(ホストはubuntu20.04を想定している)
platformioが既にインストールされている前提で説明する。

platformioのインストールについては以下などを参照のこと:
arduinoフレームワーク用platformio.ini集

platformio.ini

以下のplatformio.iniを利用する:

[env:pico] platform = https://github.com/platformio/platform-raspberrypi.git framework = arduino board = pico build_flags = -DPICO upload_port = /dev/ttyACM0 monitor_port = /dev/ttyACM0 monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = adafruit/Adafruit BusIO @ ^1.7.3 adafruit/Adafruit ST7735 and ST7789 Library @ ^1.7.1

graphicstest.ino

テスト用プログラムを以下のように作成する:
src/graphicstest.ino

// modified for pimoroni display pack (2021/4/25) /************************************************************************** This is a library for several Adafruit displays based on ST77* drivers. Works with the Adafruit 1.8" TFT Breakout w/SD card ----> http://www.adafruit.com/products/358 The 1.8" TFT shield ----> https://www.adafruit.com/product/802 The 1.44" TFT breakout ----> https://www.adafruit.com/product/2088 The 1.14" TFT breakout ----> https://www.adafruit.com/product/4383 The 1.3" TFT breakout ----> https://www.adafruit.com/product/4313 The 1.54" TFT breakout ----> https://www.adafruit.com/product/3787 The 2.0" TFT breakout ----> https://www.adafruit.com/product/4311 as well as Adafruit raw 1.8" TFT display ----> http://www.adafruit.com/products/618 Check out the links above for our tutorials and wiring diagrams. These displays use SPI to communicate, 4 or 5 pins are required to interface (RST is optional). Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. MIT license, all text above must be included in any redistribution **************************************************************************/ #include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_ST7735.h> // Hardware-specific library for ST7735 #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789 #include <SPI.h> #ifndef PICO #if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32 #define TFT_CS 14 #define TFT_RST 15 #define TFT_DC 32 #elif defined(ESP8266) #define TFT_CS 4 #define TFT_RST 16 #define TFT_DC 5 #else // For the breakout board, you can use any 2 or 3 pins. // These pins will also work for the 1.8" TFT shield. #define TFT_CS 10 #define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin #define TFT_DC 8 #endif // OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique // to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and // SCLK = pin 13. This is the fastest mode of operation and is required if // using the breakout board's microSD card. // For 1.44" and 1.8" TFT with ST7735 use: Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); // For 1.14", 1.3", 1.54", and 2.0" TFT with ST7789: //Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); // OPTION 2 lets you interface the display using ANY TWO or THREE PINS, // tradeoff being that performance is not as fast as hardware SPI above. //#define TFT_MOSI 11 // Data out //#define TFT_SCLK 13 // Clock out // For ST7735-based displays, we will use this call //Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); // OR for the ST7789-based displays, we will use this call //Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); #endif #ifdef PICO // setup for pico display pack #define TFT_CS 17 #define TFT_RST -1 #define TFT_DC 16 #define TFT_MOSI 19 // Data out #define TFT_SCLK 18 // Clock out #define BL_EN 20 // backlit enable Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); #endif float p = 3.1415926; void setup(void) { //pinMode(BL_EN, OUTPUT); //digitalWrite(BL_EN, HIGH); //Serial.begin(9600); Serial.begin(115200); Serial.print(F("Hello! ST77xx TFT Test")); #ifndef PICO // Use this initializer if using a 1.8" TFT screen: tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab // OR use this initializer if using a 1.8" TFT screen with offset such as WaveShare: // tft.initR(INITR_GREENTAB); // Init ST7735S chip, green tab // OR use this initializer (uncomment) if using a 1.44" TFT: //tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab // OR use this initializer (uncomment) if using a 0.96" 160x80 TFT: //tft.initR(INITR_MINI160x80); // Init ST7735S mini display // OR use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT: //tft.init(240, 240); // Init ST7789 240x240 // OR use this initializer (uncomment) if using a 2.0" 320x240 TFT: //tft.init(240, 320); // Init ST7789 320x240 // OR use this initializer (uncomment) if using a 1.14" 240x135 TFT: //tft.init(135, 240); // Init ST7789 240x135 // SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here // Note that speed allowable depends on chip and quality of wiring, if you go too fast, you // may end up with a black screen some times, or all the time. //tft.setSPISpeed(40000000); #endif #ifdef PICO tft.init(135, 240); // Init ST7789 240x135 //tft.setRotation(3); // landscape tft.setRotation(2); // rotate for matching printing chars on the board tft.setSPISpeed(40000000); #endif Serial.println(F("Initialized")); uint16_t time = millis(); tft.fillScreen(ST77XX_BLACK); time = millis() - time; Serial.println(time, DEC); delay(500); // large block of text tft.fillScreen(ST77XX_BLACK); testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE); delay(1000); // tft print function! tftPrintTest(); delay(4000); // a single pixel tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN); delay(500); // line draw test testlines(ST77XX_YELLOW); delay(500); // optimized lines testfastlines(ST77XX_RED, ST77XX_BLUE); delay(500); testdrawrects(ST77XX_GREEN); delay(500); testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA); delay(500); tft.fillScreen(ST77XX_BLACK); testfillcircles(10, ST77XX_BLUE); testdrawcircles(10, ST77XX_WHITE); delay(500); testroundrects(); delay(500); testtriangles(); delay(500); mediabuttons(); delay(500); Serial.println("done"); delay(1000); } void loop() { tft.invertDisplay(true); delay(500); tft.invertDisplay(false); delay(500); } void testlines(uint16_t color) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, 0, x, tft.height()-1, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, 0, tft.width()-1, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, 0, 0, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, tft.height()-1, x, 0, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, tft.height()-1, tft.width()-1, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color); delay(0); } } void testdrawtext(char *text, uint16_t color) { tft.setCursor(0, 0); tft.setTextColor(color); tft.setTextWrap(true); tft.print(text); } void testfastlines(uint16_t color1, uint16_t color2) { tft.fillScreen(ST77XX_BLACK); for (int16_t y=0; y < tft.height(); y+=5) { tft.drawFastHLine(0, y, tft.width(), color1); } for (int16_t x=0; x < tft.width(); x+=5) { tft.drawFastVLine(x, 0, tft.height(), color2); } } void testdrawrects(uint16_t color) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color); } } void testfillrects(uint16_t color1, uint16_t color2) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=tft.width()-1; x > 6; x-=6) { tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1); tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2); } } void testfillcircles(uint8_t radius, uint16_t color) { for (int16_t x=radius; x < tft.width(); x+=radius*2) { for (int16_t y=radius; y < tft.height(); y+=radius*2) { tft.fillCircle(x, y, radius, color); } } } void testdrawcircles(uint8_t radius, uint16_t color) { for (int16_t x=0; x < tft.width()+radius; x+=radius*2) { for (int16_t y=0; y < tft.height()+radius; y+=radius*2) { tft.drawCircle(x, y, radius, color); } } } void testtriangles() { tft.fillScreen(ST77XX_BLACK); uint16_t color = 0xF800; int t; int w = tft.width()/2; int x = tft.height()-1; int y = 0; int z = tft.width(); for(t = 0 ; t <= 15; t++) { tft.drawTriangle(w, y, y, x, z, x, color); x-=4; y+=4; z-=4; color+=100; } } void testroundrects() { tft.fillScreen(ST77XX_BLACK); uint16_t color = 100; int i; int t; for(t = 0 ; t <= 4; t+=1) { int x = 0; int y = 0; int w = tft.width()-2; int h = tft.height()-2; for(i = 0 ; i <= 16; i+=1) { tft.drawRoundRect(x, y, w, h, 5, color); x+=2; y+=3; w-=4; h-=6; color+=1100; } color+=100; } } void tftPrintTest() { tft.setTextWrap(false); tft.fillScreen(ST77XX_BLACK); tft.setCursor(0, 30); tft.setTextColor(ST77XX_RED); tft.setTextSize(1); tft.println("Hello World!"); tft.setTextColor(ST77XX_YELLOW); tft.setTextSize(2); tft.println("Hello World!"); tft.setTextColor(ST77XX_GREEN); tft.setTextSize(3); tft.println("Hello World!"); tft.setTextColor(ST77XX_BLUE); tft.setTextSize(4); tft.print(1234.567); delay(1500); tft.setCursor(0, 0); tft.fillScreen(ST77XX_BLACK); tft.setTextColor(ST77XX_WHITE); tft.setTextSize(0); tft.println("Hello World!"); tft.setTextSize(1); tft.setTextColor(ST77XX_GREEN); tft.print(p, 6); tft.println(" Want pi?"); tft.println(" "); tft.print(8675309, HEX); // print 8,675,309 out in HEX! tft.println(" Print HEX!"); tft.println(" "); tft.setTextColor(ST77XX_WHITE); tft.println("Sketch has been"); tft.println("running for: "); tft.setTextColor(ST77XX_MAGENTA); tft.print(millis() / 1000); tft.setTextColor(ST77XX_WHITE); tft.print(" seconds."); } void mediabuttons() { // play tft.fillScreen(ST77XX_BLACK); tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE); tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED); delay(500); // pause tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE); tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN); tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN); delay(500); // play color tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE); delay(50); // pause color tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED); tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED); // play color tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN); }

・「Adafruit ST7735 and ST7789 Library 」にあるExamplesをDisplay_Pack向けに修正したもの。
・「#ifdef PICO ... #endif」などで囲まれた部分が修正部分になる。

ビルド&書き込み

以下の手順でビルトと書き込みができる:

cd pico_proj # ツールなどのインストール(最初の1回のみ) pio run -t clean # ビルドと書き込み # bootselボタンを押しながらホストにUSB接続して # その後、bootselボタンを離すると、書き込み用ストレージが出現する pio run -t upload # この時点で書き込みが完了する

Pico_LED_SW.ino (2021/4/28)

Display_PackのLEDとSWの制御スケッチを以下に紹介する:

src/Pico_LED_SW.ino

// for pimoroni Display Pack (2021/4/28) // setup LEDs & SWs #define LED_R 6 #define LED_G 7 #define LED_B 8 #define SW_A 12 #define SW_B 13 #define SW_X 14 #define SW_Y 15 int swn = 0; int sSW_A = LOW; int sSW_B = LOW; int sSW_X = LOW; int sSW_Y = LOW; int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by void setup(void) { // init LEDs (negative logic) pinMode(LED_R, OUTPUT); digitalWrite(LED_R, HIGH); pinMode(LED_G, OUTPUT); digitalWrite(LED_G, HIGH); pinMode(LED_B, OUTPUT); digitalWrite(LED_B, HIGH); //digitalWrite(LED_R, LOW); //digitalWrite(LED_G, LOW); //digitalWrite(LED_B, LOW); // setup SWs pinMode(SW_A, INPUT_PULLUP); pinMode(SW_B, INPUT_PULLUP); pinMode(SW_X, INPUT_PULLUP); pinMode(SW_Y, INPUT_PULLUP); Serial.begin(115200); Serial.print(F("LEDs and SWs Test")); } void loop() { // set the brightness switch(swn) { case 0: analogWrite(LED_R, brightness); // other LEDs off pinMode(LED_G, OUTPUT); digitalWrite(LED_G, HIGH); pinMode(LED_B, OUTPUT); digitalWrite(LED_B, HIGH); break; case 1: analogWrite(LED_G, brightness); // other LEDs off pinMode(LED_R, OUTPUT); digitalWrite(LED_R, HIGH); pinMode(LED_B, OUTPUT); digitalWrite(LED_B, HIGH); break; case 2: analogWrite(LED_B, brightness); // other LEDs off pinMode(LED_R, OUTPUT); digitalWrite(LED_R, HIGH); pinMode(LED_G, OUTPUT); digitalWrite(LED_G, HIGH); break; default: pinMode(LED_R, OUTPUT); digitalWrite(LED_R, HIGH); pinMode(LED_G, OUTPUT); digitalWrite(LED_G, HIGH); pinMode(LED_B, OUTPUT); digitalWrite(LED_B, HIGH); analogWrite(LED_R, brightness); analogWrite(LED_G, brightness); analogWrite(LED_B, brightness); } // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } sSW_A = digitalRead(SW_A); sSW_B = digitalRead(SW_B); sSW_X = digitalRead(SW_X); sSW_Y = digitalRead(SW_Y); if (sSW_A == LOW) {swn=0; Serial.println("SW_A: pressed");} if (sSW_B == LOW) {swn=1; Serial.println("SW_B: pressed");} if (sSW_X == LOW) {swn=2; Serial.println("SW_X: pressed");} if (sSW_Y == LOW) {swn=3; Serial.println("SW_Y: pressed");} do { sSW_A = digitalRead(SW_A); sSW_B = digitalRead(SW_B); sSW_X = digitalRead(SW_X); sSW_Y = digitalRead(SW_Y); delay(50); } while ((sSW_A == LOW)||(sSW_B == LOW)||(sSW_X == LOW)||(sSW_Y == LOW)) ; }

(1)スイッチ(SW_A,SW_B,SW_X,SW_Y)を押すとスイッチの状態がシリアル出力される。
(2)SW_Aを押すとLEDが赤、SW_Bを押すとLEDが緑、SW_Xを押すとLEDが青、SW_Yを押すと白に、明るさが変化しながら光る。

ただし、Arduino純正ボードライブラリ(platformio,Arduino-IDEとも)にバグがあるようで、SW_Yは動作せず、LEDの色も混じった色になり意図したものと異なる。(pinModeのbug??)

earlephilhower版Arduino-IDE(以下のjsonファイルを設定するもの)のボードライブラリは問題が無いようで、SW_Yも正常動作するし、LEDの色も混ざらない。

https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

参考情報

Arduino-IDE関連:
Arduino-IDEでPicoを動かす

Pico-Platformio(Arduino)関連:
platformioでpicoを動かす
Official PlatformIO + Arduino IDE support for the Raspberry Pi Pico is now available!

platformio関連:
PlatformIO Core (CLI)
Arduino-IDEとPlatformioのコンパイラーの挙動の違いについて
arduinoフレームワーク用platformio.ini集
ubuntu20.04をインストールする

以上

続きを読む "Display_Packをpico_arduinoで動かす"

| | コメント (0)

2021年4月 1日 (木)

Arduino-IDEでPicoを動かす

2021/4/29
earlephilhower版専用になるがMulticoreのスケッチを追加した。

2021/4/23
もう一つの実装であるarduino純正ボード・ライブラリでの使用方法を追加した。
また、書き込みでエラーになるので、その解決方法についても記述した。

2021/4/5+
Arduno-IDEのwindows版でPicoの書き込みで
エラーになる場合の対応方法を追加した。

2021/4/4
LittleFSを使用したスケッチを追加した。

2021/4/3+
動作確認したスケッチを追加した。

2021/4/1+
初版

Pico Arduino Install

Pico Arduino Install

概要

Arduino-IDEでPicoを動かす。
ホスト環境は、ubuntu20.04とする。
なお、Arduino-IDEの最新版がインストール済みのものとする。

linuxのArduino-IDEのインストールについては以下を参照のこと。
Install the Arduino Software (IDE) on Linux

本記事は、linux版Arduino-IDEについて記述したものであるが、 ほとんど、そのままwindows版でも適応可能である。

ボード情報(*.json)のインストール

Arduino-IDEを起動して以下を実行する:
1.[ファイル]/[環境設定]を選択する
2.画面の「追加のボードマネージャーのURL」に以下を入力(追加)する

https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json # 今後、このjsonを利用したものをearlephilhower版と呼ぶことにする。

3.入力後、[OK]をクリックする
4.[ツール]/[ボード]/[ボードマネージャー]を選択する
5.検索欄に「pico」と入力する
6.検索結果から「Raspberry Pi Pico/RP2040」を選び、[インストール]をクリックする
7.インストール後、[閉じる]をクリックする

8.[ツール]/[ボード]/[Raspberry RP2040 boards]/[Raspberry Pi Pico]を選択する

以上で、ボードとして[Raspberry PiPico]が選択されたことになる。

なお、これ以外に以下のボードが選択できる:

Raspberry Pi Pico Raspberry Pi Pico (Picoprobe) Adafruit Feather RP2040 Adafruit Feather RP2040 (Picoprobe) Generic PR2040 Generic PR2040 (Picoprobe)

「(Picoprobe)」付きは、書き込みにopenocd(picoprobe)を使用するものになる。

Picoprobeを使った書き込み

Picoprobeを接続した場合、Arduino-IDEでボードを「Raspberry Pi Pico (Picoprobe)」を切り替える。その後は従来どおりの操作で書き込みができる。

以下、書き込み時の出力例:

<省略> Open On-Chip Debugger 0.10.0+dev-gd58c2ef5e-dirty (2021-03-28-18:41) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : only one transport option; autoselect 'swd' Warn : Transport "swd" was already selected adapter speed: 5000 kHz Info : Hardware thread awareness created Info : Hardware thread awareness created Info : RP2040 Flash Bank Command Info : clock speed 5000 kHz Info : SWD DPIDR 0x0bc12477 Info : SWD DLPIDR 0x00000001 Info : SWD DPIDR 0x0bc12477 Info : SWD DLPIDR 0x10000001 Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints Info : starting gdb server for rp2040.core0 on 3333 Info : Listening on port 3333 for gdb connections target halted due to debug-request, current mode: Thread xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00 target halted due to debug-request, current mode: Thread xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00 ** Programming Started ** Info : RP2040 B0 Flash Probe: 2097152 bytes @10000000, in 512 sectors target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00 ... <省略> ... target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00 target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00 ** Programming Finished ** ** Verify Started ** target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00 target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00 ** Verified OK ** ** Resetting Target ** shutdown command invoked Info : SWD DPIDR 0x0bc12477 Info : SWD DLPIDR 0x00000001

留意点:
・シリアルを使っているスケッチは、USBシリアルを前提にしているので、そのままでは動かない。
・picoprobe接続時でもシリアルが利用可能だが、USBシリアルではなく、普通のシリアルにpicobrobe経由で接続している。(したがって、picoprobe経由でシリアルを使用する場合、スケッチの「Serial」を「Serial1」に置き換えると使用できる)

サンプルスケッチ

ボード設定が完了した後は、通常のArduinoボードとして使用できる。
リセットボタンがないので、リセットボタンを押されることを前提にしているスケッチは、無限ループにするなどの工夫が必要となる。
なお、(Picoprobeを使用していない場合は)書き込み前に書き込み用ストレージ(RPI-RP2)が見える状態にする必要がある。
# ただし、ボードのUSBシリアルが有効になっている場合、
# 自動的にリセットするのでbootselボタンを押してのUSBの抜き差しは
# 不要となる

以下、実際に動かしたスケッチを挙げる:

ASCIITablePico.ino

/* ASCII table Prints out byte values in all possible formats: - as raw binary values - as ASCII-encoded decimal, hex, octal, and binary values For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII The circuit: No external hardware needed. created 2006 by Nicholas Zambetti <http://www.zambetti.com> modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ASCIITable */ void setup() { //Initialize serial and wait for port to open: //Serial.begin(9600); Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); } // first visible ASCIIcharacter '!' is number 33: int thisByte = 33; // you can also write ASCII characters in single quotes. // for example, '!' is the same as 33, so you could also use this: // int thisByte = '!'; void loop() { // prints value unaltered, i.e. the raw binary version of the byte. // The Serial Monitor interprets all bytes as ASCII, so 33, the first number, // will show up as '!' Serial.write(thisByte); Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. // this also works if you uncomment it: // Serial.print(thisByte, DEC); Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): Serial.print(thisByte, HEX); Serial.print(", oct: "); // prints value as string in octal (base 8); Serial.print(thisByte, OCT); Serial.print(", bin: "); // prints value as string in binary (base 2) also prints ending line break: Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: if (thisByte == 126) { // you could also use if (thisByte == '~') { thisByte = 33-1; Serial.println("----------------------------------------------"); Serial.println(""); delay(500); /* // This loop loops forever and does nothing while (true) { continue; } */ } // go on to the next character thisByte++; }

・標準に提供されているスケッチを無限ループにしたもの。
・シリアルはUSBシリアルを使用する。

Blink.ino

/* Blink Turns an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to the correct LED pin independent of which board is used. If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at: https://www.arduino.cc/en/Main/Products modified 8 May 2014 by Scott Fitzgerald modified 2 Sep 2016 by Arturo Guadalupi modified 8 Sep 2016 by Colby Newman This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Blink */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }

・標準に提供されているスケッチが無修正で動作する。

bootselBlink.ino
bootselボタンをLED点滅のボタンに使用したスケッチ(トグル動作)

// bootselBlink int toggle = false; void setup() { Serial.begin(115200); delay(5000); // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); //Serial.println("I dare you to hit the BOOTSEL button..."); } int c = 0; void loop() { if (toggle) digitalWrite(LED_BUILTIN, HIGH); else digitalWrite(LED_BUILTIN, LOW); if (BOOTSEL) { Serial.printf("You pressed BOOTSEL %d times!\n", ++c); toggle = !toggle; // Wait for BOOTSEL to be released while (BOOTSEL) { delay(1); } } }

temperature.ino
CPUのコア温度を測ってシリアルに出力するスケッチ

/* Released into the public domain */ void setup() { Serial.begin(115200); delay(5000); } void loop() { Serial.printf("Core temperature: %2.1fC\n", analogReadTemp()); delay(1000); }

・このスケッチはearlephilhower版専用となる。

fade.ino

/* Fade This example shows how to fade the onboard Raspberry Pi Pico LED This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Fade */ int led = LED_BUILTIN; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by // the setup routine runs once when you press reset: void setup() { // declare pin to be an output: pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // set the brightness analogWrite(led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } // wait for 30 milliseconds to see the dimming effect //delay(30); delay(15); }

morse_blinky.ino
シリアルから入力した文字列をLED点滅のモールス信号で出力するスケッチ
(pico-sdkのサンプルのaruduino移植版)

// ported into Arduino platform on 2021/4/4 // modified on 2021/2/6 /** * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause */ /* #include <stdio.h> #include "pico/stdlib.h" #include "hardware/gpio.h" */ char str[100]; const uint LED_PIN = 25; const uint DOT_PERIOD_MS = 100; const char *morse_letters[] = { ".-", // A "-...", // B "-.-.", // C "-..", // D ".", // E "..-.", // F "--.", // G "....", // H "..", // I ".---", // J "-.-", // K ".-..", // L "--", // M "-.", // N "---", // O ".--.", // P "--.-", // Q ".-.", // R "...", // S "-", // T "..-", // U "...-", // V ".--", // W "-..-", // X "-.--", // Y "--.." // Z }; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); //Initialize serial and wait for port to open: Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } } void put_morse_letter(const char *pattern) { for (; *pattern; ++pattern) { //gpio_put(LED_PIN, 1); digitalWrite(LED_BUILTIN, HIGH); if (*pattern == '.') //sleep_ms(DOT_PERIOD_MS); delay(DOT_PERIOD_MS); else //sleep_ms(DOT_PERIOD_MS * 3); delay(DOT_PERIOD_MS * 3); //gpio_put(LED_PIN, 0); digitalWrite(LED_BUILTIN, LOW); //sleep_ms(DOT_PERIOD_MS * 1); delay(DOT_PERIOD_MS * 1); } //sleep_ms(DOT_PERIOD_MS * 2); delay(DOT_PERIOD_MS * 2); } void put_morse_str(const char *str) { for (; *str; ++str) { if (*str >= 'A' && *str <= 'Z') { put_morse_letter(morse_letters[*str - 'A']); } else if (*str >= 'a' && *str <= 'z') { put_morse_letter(morse_letters[*str - 'a']); } else if (*str == ' ') { //sleep_ms(DOT_PERIOD_MS * 4); delay(DOT_PERIOD_MS * 4); } } } void loop() { Serial.printf("Enter String for Morse\n"); delay(1000); if (Serial.available()){ String sline = Serial.readStringUntil('\n'); sline.toCharArray(str, 100); Serial.printf("morse: %s\n", str); put_morse_str(str); } } /* int main() { stdio_init_all(); gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); while (true) { printf("Enter String for Morse\n"); fflush(stdin); scanf("%s",str); //gets(str); // does not work?? printf("morse: %s\n", str); //puts(str); //put_morse_str("Hello world"); put_morse_str(str); //sleep_ms(1000); } } */

内蔵ファイルシステム(FLASH)を使用したスケッチ

Pico用のLittleFSの書き込みツールを以下の手順でインストールする:

cd ~Downloads wget https://github.com/earlephilhower/arduino-pico-littlefs-plugin/releases/download/0.2.0/PicoLittleFS-0.2.0.zip # ダウンロードしたzipを解凍して # そのなかの picolittlefs.jar を次のディレクトリにコピーする mkdir -p ~/Arduino/tools/PicoLittleFS/tool cd ~/Arduino/tools/PicoLittleFS/tool #確認 ls picolittlefs.jar # Arduino-IDEを再起動する

スケッチのディレクトリ「FSUploadPico」にファイルシステムのデータ用の ディクトリ「data」を作り、保存したいファイルを置く。

cd FSUploadPico mkdir data cd data gedit file1.txt #任意のテキスト内容を編集する

FSUploadPico.ino

// Released to the public domain // // This sketch will read an uploaded file and increment a counter file // each time the sketch is booted. // Be sure to install the Pico LittleFS Data Upload extension for the // Arduino IDE from: // https://github.com/earlephilhower/arduino-pico-littlefs-plugin/ // The latest release is available from: // https://github.com/earlephilhower/arduino-pico-littlefs-plugin/releases // Before running: // 1) Select Tools->Flash Size->(some size with a FS/filesystem) // 2) Use the Tools->Pico Sketch Data Upload tool to transfer the contents of // the sketch data directory to the Pico #include <LittleFS.h> void setup() { Serial.begin(115200); delay(5000); LittleFS.begin(); char buff[32]; int cnt = 1; File f = LittleFS.open("counts.txt", "r"); if (f) { bzero(buff, 32); if (f.read((uint8_t *)buff, 31)) { sscanf(buff, "%d", &cnt); Serial.printf("I have been run %d times\n", cnt); } f.close(); } cnt++; sprintf(buff, "%d\n", cnt); f = LittleFS.open("counts.txt", "w"); if (f) { f.write(buff, strlen(buff)); f.close(); } Serial.println("---------------"); while(true) { File i = LittleFS.open("file1.txt", "r"); if (i) { while (i.available()) { Serial.write(i.read()); } Serial.println("---------------"); i.close(); } } // while forever } void loop() { }

・リセットボタンがないのでシリアル出力部分を無限ループに変更した。
・ボードのライブラリが最新版である必要がある。(ボードマネージャーで更新する)

書き込みと実行:
以下の手順でdata書き込みとスケッチの書き込みを行なう:
(1)Arduino-IDEで[ツール(tools)]/[Flash Size]で任意(ゼロ以外)を設定する
(2)Arduino-IDEで[ツール(tools)]/[PicoLittleFS Data Upload]を選択して dataディレクトリの内容をPicoのflashに書き込む
(3)書き込み(Upload)アイコンを押してスケッチのコンパイルと書き込みを実行する

出力例(USBシリアル):

# 以下のfile1.txtの内容を繰り返し出力する Hello! Welcome to the Raspberry Pi Pico using arduino-pico! this is LittleFS test#1. this is LittleFS test#2. this is LittleFS test#3. this is LittleFS test#4. this is LittleFS test#5. this is LittleFS test#6.

windows版Arduino-IDEでの書き込みエラーの対応方法

windows版Arduino-IDEでは、動作環境によっては、Pico書き込み時にエラーになり書き込めないことがある。

これは、windowsのドライブのボリューム名として、半角カタカナが使われている場合、 書き込みツールとして使用しているuf2conv.pyでutf8文字列変換がエラーになっていることが原因である。

この対応として、日本語のボリューム名を英語などに変更することで、エラーを回避でき、書き込みが正常に動作するようになる。

または、ボリューム名を(手動で)変更せずにwindowsのシステム言語を英語に変更することでボリューム名も英語に変更することで書き込みが可能になる。
ここでは、システム言語を変更する方法でエラーを回避する。

システム言語を英語にする方法については以下などを参照のこと:
Windows 10 表示言語を英語版にする

重要な注意:
[Windows display], [Apps & websites]のみを英語に変更すること。 他も英語にすると日本語キーボードなどが使用できなくなるなどの不都合が生じる。

参考:
日本語から英語にシステム言語を変更すると、uf2conv.pyの変数r(bytearray)の内容が以下のように変化する:(環境依存あり)

日本語の場合: b'DeviceID DriveType FileSystem VolumeName \r\r\nC: 3 NTFS Windows \r\r\nD: 3 NTFS \x83{\x83\x8a\x83\x85\x81[\x83\x80 \r\r\nE: 2 FAT RPI-RP2 \r\r\n\r\r\n' 英語の場合: b'DeviceID DriveType FileSystem VolumeName \r\r\nC: 3 NTFS Windows \r\r\nD: 3 NTFS Volume \r\r\nE: 2 FAT RPI-RP2 \r\r\n\r\r\n'

・この例ではドライブDのボリューム名が変化していることが分かる。
・「\x83{\x83\x8a\x83\x85\x81[\x83\x80」(83 7B 83 8A 83 85 81 5B 83 80)は半角カナの部分になる。

他の対応方法としては、uf2conv.pyの変数rの中の半角カナ部分をutf8変換可能な文字に置き換えるパッチが考えられる。
それには以下のように修正する:
uf2conv.py

#修正前 def to_str(b): return b.decode("utf-8") ↓ #修正後 def to_str(b): return b.decode("utf-8",errors="replace")


Multicore用スケッチ (2021/4/29)

PicoはDualCoreのCPUなので、2つのCPUをスケッチで動作させることができる。
以下のexamplesにあったものを掲載する。
examples(earlephilhower)

残念ながら自分の環境では1コア(core0)としてしか動作しなかった。
(今後のupdateでfixするものと思われる)

Multicore.ino

// Demonstrates a simple use of the setup1()/loop1() functions // for a multiprocessor run. // Will output something like, where C0 is running on core 0 and // C1 is on core 1, in parallel. // 11:23:07.507 -> C0: Blue leader standing by... // 11:23:07.507 -> C1: Red leader standing by... // 11:23:07.507 -> C1: Stay on target... // 11:23:08.008 -> C1: Stay on target... // 11:23:08.505 -> C0: Blue leader standing by... // 11:23:08.505 -> C1: Stay on target... // 11:23:09.007 -> C1: Stay on target... // 11:23:09.511 -> C0: Blue leader standing by... // 11:23:09.511 -> C1: Stay on target... // 11:23:10.015 -> C1: Stay on target... // Released to the public domain // The normal, core0 setup void setup() { Serial.begin(); delay(5000); } void loop() { Serial.printf("C0: Blue leader standing by...\n"); delay(1000); } // Running on core1 void setup1() { delay(5000); Serial.printf("C1: Red leader standing by...\n"); } void loop1() { Serial.printf("C1: Stay on target...\n"); delay(500); }

・このスケッチはearlephilhower版専用となる。

Arduino純正のボード・ライブラリを使用する(2021/4/23)

最近、Arduino純正のボード・ライブラリもサポートされたので、その使い方について述べる。
純正ライブラリなので.jsonの設定などは不要で、ボード・ライブラリのアップデートをするだけで良い。
(この版をearlephilhower版と区別するために純正版と呼ぶ)

ボード・ライブラリ設定は以下の手順で行なう:

(1)[ツール(tools)]/[ボードマネージャ]を選択する。 (2)「pico」で検索する。 (3)検索された候補のなかで[Arduino Mbed OS RP2040 Boards]を選択する。 (4)[インストール]をクリックする。 (5)[閉じる]をクリックする。

ボードを選択するためには以下の手順で行なう:

(1)[ツール(tools)]/[Arduino Mbed OS RP2040 Boards]/[Raspberry Pi Pico]を選択する。 (2)[ツール(tools)]/[シリアルポート]を選択する。

あとは、通常の方法でビルドと書き込みができる。

重要:
書き込み時にエラーになった場合、udev-ruleが登録されていない可能性があるので、
その場合、以下を実行してudev-ruleを登録する:

sudo ~/.arduino15/packages/arduino/hardware/mbed_rp2040/2.0.0/post_install.sh

書き込みが正常に動作すると以下のようなメッセージが出る:
(設定で「より詳細な情報を表示する:」で[書き込み]にチェックしている場合)

/home/xxxx/.arduino15/packages/arduino/tools/rp2040tools/1.0.2/rp2040load -v -D /tmp/arduino_build_yyyyy/zzzzz.ino.elf rp2040load 1.0.1 - compiled with go1.15.8 Loading into Flash: [==============================] 100%%

参考情報

earlephilhower版関連:
Arduino-Pico(Detailed Documentation)
examples(earlephilhower)

Pico-Arduino関連:
Arduino IDE support for RP2040 and Pico arrives
Display_Packをpico_arduinoで動かす

Arduino関連:
Arduino-Pico
Install the Arduino Software (IDE) on Linux
How to Program Raspberry Pi Pico With the Arduino IDE
pico-setup-windows installer
Arduino IDEライブラリのインストールとディレクトリ(フォルダ)構成 (Windows, Mac, Linux対応)

FS関連:
Arduino Pico LittleFS Filesystem Uploader
Filesystem
LittleFS
Arduino ESP8266 LittleFS Filesystem Uploader

OpenOCD関連:
PicoボードにPico_SDKでC言語をビルドする(Picoprobeの説明あり)
Debugging the Raspberry Pi Pico on Windows 10

Pico関連:
Raspberry Pi Pico – How to Interface (almost) Everything!

WSL2関連:
WSL2でRDPサーバーを動かす
WSL2でSSHサーバーを動かす
WSL2でのplatformioやPico-SDKの利用方法

python3関連:
How to permissively decode a UTF-8 bytearray?
bytes, bytearray/日本語エンコード名

その他:
文字コードの16進ダンプ

以上

続きを読む "Arduino-IDEでPicoを動かす"

| | コメント (0)

2021年3月 7日 (日)

platformioのプログラムをArduino-IDEにインポートする方法

2021/3/6
初版

import platformio to Arduino-IDE

import platformio to Arduino-IDE

概要

platformioのプログラムをArduino-IDEにインポートする方法について述べる。
以下を前提とする:
(1)platformioのframeworkとして、arduinoに設定している
(2)Arduino-IDEは、インストール済みで使用するボードのボードマネージャーでの設定が完了している
(3)Arduino-IDEのディレクトリ構成はデフォルトのままとする
(4)ホストPCのOSとしてubuntuを使用している

インポート作業の流れとしては以下になる:
(1)platformioのプログラムをArduinoのディレクトリにコピーする
(2)platformioで使用しているライブラリをArduino/librariesにコピーする

実際の手順

ここでは例として、platformioのwiot-nixie-NTP(ディレクトリ)のプログラムを Arduino-IDEにインポートすることにする。

cd pio_ws # プログラムをコピーする cp -r wiot-nixie-NTP/src ~/Arduino/wiot-nixie-NTP mv ~/Arduino/wiot-nixie-NTP/*.ino ~/Arduino/wiot-nixie-NTP/wiot-nixie-NTP.ino cd wiot-nixie-NTP # ライブラリをダウンロードする # (以前、ビルドしたことがあれば不要) pio run # ライブラリをコピーする cp -r .pio/libdeps/seeed_wio_terminal/* ~/Arduino/libraries/

ここで「seeed_wio_terminal」は、ボード名称になるので、自分の状況にあわせて変更すること。

参考情報

スケッチ関連:
nixieクロックにNTPクライアントの機能を追加する(V2)
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)

PlatformIO関連:
arduinoフレームワーク用platformio.ini集
windows10にplatformioをインストールする(scoop版)
WSL2でのplatformioやPico-SDKの利用方法
PlatformIO Core (CLI)

Arduino-IDE関連:
Arduino IDEをUbuntu 20.04にインストールする
How to add boards in the board manager
Customizing the Arduino IDE
Arduino IDEライブラリのインストールとディレクトリ(フォルダ)構成 (Windows, Mac, Linux対応)
A Tour Inside Arduino Core: Source Files, How to Make A New Core and Arduino Building Steps

以上

続きを読む "platformioのプログラムをArduino-IDEにインポートする方法"

| | コメント (0)

2021年2月21日 (日)

arduinoフレームワーク用platformio.ini集

2021/2/21+
初版

platformio.ini for arduino

platformio.ini for arduino

概要

arduinoフレームワーク用platformio.ini集
本記事は。各ボード用のplatformio.iniを集め、platformioの使い方を説明したものである。
(ホストはubuntu20.04を想定している)

準備

開発ツールをインストールする前に 必要なものをインストールする:

sudo apt update sudo apt install net-tools sudo apt install git curl sudo apt install gcc-arm-none-eabi build-essential sudo apt install cmake sudo apt install libusb-dev sudo apt install libusb-1.0-0-dev sudo apt install picocom sudo apt install python3-distutils sudo apt install python3-venv # lib for Arduino IDE for microbit sudo apt install libudev1:i386 # for Arduino IDE for ESP32/ESP8266 sudo apt install python-is-python3 pip install pyserial pip uninstall serial

bt(bootterm)のインストール

git clone https://github.com/wtarreau/bootterm cd bootterm make sudo make install

本ツールは、コマンドとして「bt」と入力すると最近有効になった「/dev/ttyACMx または /dev/ttyUSBx」に接続する。
参照:Bootterm – a developer-friendly serial terminal program

PlatformIOのインストール

python3 -m venv pio_env source pio_env/bin/activate pip install platformio インストール後も、このツールを使用する場合 同じディレクトリで以下を実行する: source pio_env/bin/activate # 「source」は、「.」でも良い

udev登録

以下を実行して、udevのrulesを登録する:

curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules sudo udevadm control --reload-rules sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER

platformioの使い方

# プロジェクトのディレクトリを作る # (一つのスケッチごとに一つのディレクトリ) mkdir proj cd proj # ソースを置くディレクトリsrcを作る mkdir src # スケッチを作成する # (テスト用には以降に出てくるsrc/ASCIItable.inoを使用する) gedit src/xxxx.ino # 使うボードに対応したplatformio.iniを作る # (内容は以降に出てくるplatform.iniをそのままコピーする) gedit platformio.ini # スケッチをビルドする # (最初の1回はライブラリ・ツールを自動的にダウンロードする) pio run # ボードをUSB接続して書き込む pio run -t upload # USBシリアルを使っているスケッチならば # 以下のコマンドでシリアル接続して出力を表示させる bt # または picocom -b115200 /dev/ttyACM0 (または/dev/ttyUSB0)

その他の使い方

# build結果をクリアする pio run -t clean # キャッシュをクリアする # (ツールやライブラリがダウンロードし直しになるので注意のこと) sudo rm -r .pio # 環境を切り替えて書き込む pio run -e f303 -t upload pio run -e f103 -t upload

環境を切り替えて書き込む場合のplatformio.iniは
以下のように複数の環境[env:xxx]を持っていること:
platformio.ini

[env:f103] platform = ststm32 board = nucleo_f103rb framework = arduino build_flags = -DNUCLEO_F103RB monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = stlink #lib_deps = [env:f303] platform = ststm32 board = nucleo_f303k8 framework = arduino build_flags = -DNUCLEO_F303K8 monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = stlink #lib_deps =

[env:xxxx]のxxxxの部分は環境名にあたり、 ダブらない任意の名前であること。

テスト用スケッチ

src/ASCIItable.ino

/* ASCII table Prints out byte values in all possible formats: - as raw binary values - as ASCII-encoded decimal, hex, octal, and binary values For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII The circuit: No external hardware needed. created 2006 by Nicholas Zambetti <http://www.zambetti.com> modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ASCIITable */ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); } // first visible ASCIIcharacter '!' is number 33: int thisByte = 33; // you can also write ASCII characters in single quotes. // for example, '!' is the same as 33, so you could also use this: // int thisByte = '!'; void loop() { // prints value unaltered, i.e. the raw binary version of the byte. // The Serial Monitor interprets all bytes as ASCII, so 33, the first number, // will show up as '!' Serial.write(thisByte); Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. // this also works if you uncomment it: // Serial.print(thisByte, DEC); Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): Serial.print(thisByte, HEX); Serial.print(", oct: "); // prints value as string in octal (base 8); Serial.print(thisByte, OCT); Serial.print(", bin: "); // prints value as string in binary (base 2) also prints ending line break: Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: if (thisByte == 126) { // you could also use if (thisByte == '~') { // This loop loops forever and does nothing while (true) { continue; } } // go on to the next character thisByte++; }

本スケッチはarduinoのサンプルそのもの(bpsのみ変更)である。

plaformio.ini

(1)platformio.iniの先頭にあたる以下はコメントにあたるので省略している:

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags ; Library options: dependencies, extra library storages ; Advanced options: extra scripting ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html

(2)追加するライブラリがある場合は以下のように 「lib_dep= 」以降にライブラリのurlなどを追加する:

lib_deps = #https://github.com/arduino-libraries/NTPClient.git arduino-libraries/NTPClient@^3.1.0

(3)以下、各ボード用のplatformio.iniになる。

Arduino Uno

[env:uno] platform = atmelavr board = uno framework = arduino #build_flags = -Dxxxx upload_protocol = arduino monitor_speed = 115200 lib_ldf_mode = deep+ #lib_deps =

wio-temirnal

[env:seeed_wio_terminal] platform = atmelsam board = seeed_wio_terminal framework = arduino build_flags = -DWIO_TERMINAL upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # 551 #https://github.com/arduino-libraries/NTPClient.git arduino-libraries/NTPClient@^3.1.0

XIAO

[env:seeed_xiao] platform = atmelsam board = seeed_xiao framework = arduino build_flags = -DXIAO upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = olikraus/U8g2 @ ^2.28.7

Feather M4

[env:adafruit_feather_m4] platform = atmelsam board = adafruit_feather_m4 framework = arduino build_flags = -DFEATHER_M4 upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ #lib_deps =

Grand Central M4

[env:adafruit_grandcentral_m4] platform = atmelsam board = adafruit_grandcentral_m4 framework = arduino build_flags = -DGRANDCENTRAL_M4 upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ #lib_deps =

M5Atom

[env:esp32dev] platform = espressif32 #board = esp32dev board = m5stick-c framework = arduino build_flags = -DM5ATOM monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = # use M5Atom lib 3113 # use "FastLED" 126

M5StickC

[env:esp32dev] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5STICK_C monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = m5stack/M5StickC @ ^0.2.0

リセット方法:
(1)「M5」と書かれたボタンを正面に見て左側にあるボタンを6秒長押して電源を切る。
(2)そのボタンを再度、2秒長押しをして電源を入れる。(リセットになる)



M5StickCPlus

[env:esp32dev] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5STICK_CP monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = m5stack/M5StickCPlus @ ^0.0.1

リセット方法:
(1)「M5」と書かれたボタンを正面に見て左側にあるボタンを6秒長押して電源を切る。
(2)そのボタンを再度、2秒長押しをして電源を入れる。(リセットになる)



M5Stack Fire

[env:esp32dev] platform = espressif32 board = m5stack-fire framework = arduino build_flags = -DM5STACK_FIRE monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = m5stack/M5Stack https://github.com/lovyan03/LovyanGFX.git

Power on/off:
・Power on: click the red power button on the left
・Power off: Quickly double-click the red power button on the left



ESP32

[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino build_flags = -DESP32 monitor_speed = 115200 lib_ldf_mode = deep+ #lib_deps =

ESP8266

[env:huzzah] platform = espressif8266 board = esp_wroom_02 framework = arduino build_flags = -DESP8266 monitor_speed = 115200 lib_ldf_mode = deep+ #lib_deps =

micro:bit

[env:bbcmicrobit] platform = nordicnrf51 board = bbcmicrobit framework = arduino build_flags = -DMICROBIT -DNRF51_S110 monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = cmsis-dap lib_deps = https://github.com/adafruit/Adafruit_BusIO/archive/master.zip https://github.com/sparkfun/SparkFun_MAG3110_Breakout_Board_Arduino_Library/archive/master.zip https://cdn-learn.adafruit.com/assets/assets/000/046/217/original/MMA8653.zip https://github.com/stm32duino/LSM303AGR/archive/master.zip https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip # https://github.com/sandeepmistry/arduino-BLEPeripheral/archive/master.zip https://github.com/adafruit/Adafruit_Microbit/archive/master.zip # https://github.com/ht-deko/microbit_Screen/archive/master.zip

Nucleo STM32F103RB

[env:nucleo_f103rb] platform = ststm32 board = nucleo_f103rb framework = arduino build_flags = -DNUCLEO_F103RB monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = stlink #lib_deps =

Nucleo STM32F303K8

[env:nucleo_f303k8] platform = ststm32 board = nucleo_f303k8 framework = arduino build_flags = -DNUCLEO_F303K8 monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = stlink #lib_deps =

TeensyLC

[env:teensylc] platform = teensy board = teensylc framework = arduino #build_flags = -Dxxxx monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = teensy-cli #lib_deps =

Teensy3.6

[env:teensy36] platform = teensy board = teensy36 framework = arduino #build_flags = -Dxxxx monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = teensy-cli #lib_deps =

Teensy4.0

[env:teensy40] platform = teensy board = teensy40 framework = arduino #build_flags = -Dxxxx monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = teensy-cli #lib_deps =

ビルド・エラー

Arduino-IDEのコンパイラと異なり、platformioのコンパイラは、関数定義の後方参照を許さないので、 この場合、関数の未定義エラーになる。したがって、Arduino-IDEでビルドできているソースでもエラーになることがある。このときの対応方法は、未定義エラーになる関数定義をプロトタイプ宣言としてソースの先頭に置き、後方参照を解消する。(関数定義の本体の位置はそのままで移動させる必要はない)

参考情報

M5Stack関連:
PlatformIO M5Stack開発の現状
・https://github.com/m5stack/M5StickC-Plus.git
・https://github.com/m5stack/M5StickC.git
・https://github.com/m5stack/M5Stack.git

micro:bit関連:
micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版)
micro:bit v2 で遊ぶ

platformio関連:

https://docs.platformio.org/en/latest/platforms/creating_board.html Installation 1.Create boards directory in core_dir if it doesn’t exist. 2.Create myboard.json file in this boards directory. 3.Search available boards via pio boards command. You should see myboard board.

PlatformIO Core (CLI)
Arduino-IDEとPlatformioのコンパイラーの挙動の違いについて
ubuntu20.04をインストールする

以上

続きを読む "arduinoフレームワーク用platformio.ini集"

| | コメント (0)

より以前の記事一覧