Loading... **BPI:bit Webduino是BPI与Webduino合作出品的一块主打STEAM创客教育的一款产品。** github地址:[https://github.com/yelvlab/BPI-bit_Webduino](https://github.com/yelvlab/BPI-bit_Webduino) <!--more--> 开发板[详细信息](http://forum.banana-pi.org/t/bpi-webduino-bit-board-for-steam-education/4854)  <p>具体硬件不做多介绍,下面开始说关于基础功能测试部分。</p> ## 软件环境: Atom+PlatformIO/VS Code+PlatformIO(两个都可以,我也两个都安装了,各有长处,唯一的缺点就是都需要科学上网) 扩展包:ESP32平台包&NeoPixelBus库 ## 测试内容: 1. WS2812可编程全色彩LED测试循环三次(显示颜色顺序:Red、Blue、Green、white、Black) 2. ADC采样三次(通道:ADC1_CH0(LUM0)/ADC1_CH3(LUM1)/ADC1_CH6(TEMP)) 3. Wi-Fi扫描一次(扫描可用Wi-Fi信号以及信号强度) 4. 蜂鸣器测试三次(采用占空比渐变的方式循环测试三次) 状态监控:通过串口查看测试状态(串口配置:115200-8-N-1) 测试视频:[Banana pi BPI-webduino:bit function demo](https://www.youtube.com/watch?v=auTURJdbIYE&feature=youtu.be)(视频来自油管) </ul> ## 测试代码 //BIT NEW //BPI - BIT test code #include <Arduino.h> #include <NeoPixelBus.h> #include "WiFi.h" #define LEDC_CHANNEL_0 0 #define LEDC_TIMER_13_BIT 13 #define LEDC_BASE_FREQ 4500 const char *ssid = "SSID"; const char *password = "PASSWD"; const uint16_t PixelCount = 25; const uint8_t PixelPin = 4; #define colorSaturation 64 #define delay_ms 500 #define bout 3 NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin); RgbColor red(colorSaturation, 0, 0); RgbColor green(0, colorSaturation, 0); RgbColor blue(0, 0, colorSaturation); RgbColor white(colorSaturation); RgbColor black(0); HslColor hslRed(red); HslColor hslGreen(green); HslColor hslBlue(blue); HslColor hslWhite(white); HslColor hslBlack(black); #define LUM0 36 //ADC1_CH0 #define LUM1 39 //ADC1_CH3 #define Temp 34 #define Buzzer 25 #define BottomA 35 #define BottomB 27 int LUM_Value0 = 0; int LUM_Value1 = 0; int Temp_value = 0; int adTestFreq = 0; int wifiTestFreq = 0; int ledTestFreq = 0; int BuzzerTestFreq = 0; int brightness = 0; int fadeAmount = 5; void ledcAnalogWrite(uint8_t channel, uint32_t value) { // calculate duty, 8191 from 2 ^ 13 - 1 (2 ^ LEDC_TIMER_13_BIT - 1) //value_MAX = 255 uint32_t duty = (8191 / 255) * value; // write duty to LEDC ledcWrite(channel, duty); } void setup() { Serial.begin(115200); //Serial Port Config 115200-8-N-1 while (!Serial) ; // wait for serial attach Serial.println(); Serial.println("Initializing..."); Serial.flush(); // this resets all the neopixels to an off state strip.Begin(); strip.Show(); Serial.println(); Serial.println("BPI-BIT Function Test Demo"); Serial.println("Running..."); Serial.println(); ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT); ledcAttachPin(Buzzer, LEDC_CHANNEL_0); } void loop() { /************************************************************** ************************************************************** ***Board:BPI-Webduino:BIT *** ***Function:LED(WS2812) Test *** ************************************************************** *************************************************************/ Serial.println(); Serial.println("LED test!!!"); Serial.println(); for (ledTestFreq = 0; ledTestFreq < bout; ledTestFreq++) { int i; delay(delay_ms); Serial.println("Colors R"); for (i = 0; i <= PixelCount - 1; i++) { strip.SetPixelColor(i, hslRed); strip.Show(); } delay(delay_ms); Serial.println("Colors B"); for (i = 0; i <= PixelCount - 1; i++) { strip.SetPixelColor(i, hslBlue); strip.Show(); } delay(delay_ms); Serial.println("Colors G"); for (i = 0; i <= PixelCount - 1; i++) { strip.SetPixelColor(i, hslGreen); strip.Show(); } delay(delay_ms); Serial.println("Colors W"); for (i = 0; i <= PixelCount - 1; i++) { strip.SetPixelColor(i, hslWhite); strip.Show(); } delay(delay_ms); Serial.println("Turn Off"); for (i = 0; i <= PixelCount - 1; i++) { strip.SetPixelColor(i, hslBlack); strip.Show(); } Serial.println(); } Serial.println("--Over--"); /************************************************************** ************************************************************** ***Board:BPI-Webduino:BIT *** ***Function:ADC Test *** ************************************************************** *************************************************************/ Serial.println(); Serial.println("ADC test!!!"); Serial.println(); for (adTestFreq = 0; adTestFreq < bout; adTestFreq++) { // turn the LED on (HIGH is the voltage level) LUM_Value0 = analogRead(LUM0); LUM_Value1 = analogRead(LUM1); Temp_value = analogRead(Temp); Serial.println(); Serial.println("----LUM&Temp Test(AD Test)----"); //LUM0--ADC1_CH0-Pin:IO36 Serial.print("LUM0:"); Serial.print(LUM_Value0); Serial.println(); //LUM1--ADC1_CH3-Pin:IO39 Serial.print("LUM1:"); Serial.print(LUM_Value1); Serial.println(); //Temp--ADC2_CH7-Pin:IO27 Serial.print("TEMP:"); Serial.print(Temp_value); Serial.println(); delay(delay_ms); Serial.println(); } Serial.println("--Over--"); /************************************************************** ************************************************************** ***Board:BPI-Webduino:BIT *** ***Function:Wi-Fi Test *** ************************************************************** *************************************************************/ Serial.println(); Serial.println("Wi-Fi test!!!"); Serial.println(); // //Wi-Fi connect // Serial.print("Connecting to "); // Serial.println(ssid); // WiFi.begin(ssid, password); // while (WiFi.status() != WL_CONNECTED) // { // delay(500); // Serial.print("."); // } // Serial.println("WiFi connected"); // Serial.println("IP address: "); // Serial.println(WiFi.localIP()); // Serial.println("Setup done"); // Serial.println(""); // WiFi.disconnect(); for (wifiTestFreq = 0; wifiTestFreq < 1; wifiTestFreq++) { Serial.println("scan start"); // WiFi.scanNetworks will return the number of networks found int n = WiFi.scanNetworks(); Serial.println("scan done"); if (n == 0) { Serial.println("no networks found"); } else { Serial.print(n); Serial.println(" networks found"); for (int j = 0; j < n; ++j) { // Print SSID and RSSI for each network found Serial.print(j + 1); Serial.print(": "); Serial.print(WiFi.SSID(j)); Serial.print(" ("); Serial.print(WiFi.RSSI(j)); Serial.print(")"); Serial.println((WiFi.encryptionType(j) == WIFI_AUTH_OPEN) ? " " : "*"); delay(10); } } Serial.println(""); // Wait a bit before scanning again delay(2000); } Serial.println("--Over--"); /************************************************************** ************************************************************** ***Board:BPI-Webduino:BIT *** ***Function:Buzzer Test *** ************************************************************** *************************************************************/ Serial.println(); Serial.println("Buzzer Test!!!"); Serial.println(); Serial.println("Buzzer is fading"); for (BuzzerTestFreq = 0; BuzzerTestFreq < bout; BuzzerTestFreq++) { for (brightness = 0; brightness < 255; brightness++) { Serial.print("."); // set the brightness on LEDC channel 0 ledcAnalogWrite(LEDC_CHANNEL_0, 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); } Serial.println(); ledcAnalogWrite(LEDC_CHANNEL_0, 0); } Serial.println("--Over--"); Serial.println("---------Test Over !!!---------"); } Last modification:March 26, 2018 © Allow specification reprint Like 0 If you think my article is useful to you, please feel free to appreciate