TA的每日心情 | 开心 2021-12-10 15:56 |
---|
签到天数: 2675 天 连续签到: 1 天 [LV.Master]伴坛终老
|
本帖最后由 slotg 于 2016-11-20 16:27 编辑
并不是每一个 Arduino AVR 的程序都可以直接使用在 Arduino STM32 板上的,点完了 LCD 之后接下来也要试一下 OLED 的驱动,找了一个使用 Adafruit 库在 Arduino AVR 板上可以运行的例程直接在 STM32 下编译,结果却产生了错误!这貌似是库的支持不兼容,问题目前还在确认中,不过在 Arduino 官网论坛看到了这一篇帖子:
http://forum.arduino.cc/index.php?topic=265904.2115
有人改写了 Adafruit_SSD1306 库,让这个库可以在 Arduino STM32 底下运行,程序中对于 SPI 接口方式的 OLED 管脚是这么声明的:
#define OLED_DC 22 // D/C 6
#define OLED_RST 21 // RST 5
#define OLED_MOSI 20 // SDA 4
#define OLED_CLK 19 // SCL 3
#define OLED_CS 14 // --- x Not Connected
对应于 Arduino STM32 板的管脚为:
22 -> B6
21 -> B5
20 -> B4
19 -> B3
14 -> A14
主程序:- /*
- Using Display: http://www.ebay.com/itm/301504841805
- Compiled Arduino GUI 1.6.1 on 2015-04-01 by M. Ray Burnette
- Sketch uses 27,912 bytes (25%) of program storage space. Maximum is 108,000 bytes.
- Global variables use 5,616 bytes of dynamic memory.
- THIS VERSION OF SSD1306 IS SOFTWARE SPI ONLY!!!
- https://github.com/hwiguna/g33k/blob/master/ArduinoProjects/128x64_OLED/HariChord/HariChord.ino
- */
- #include ".\Adafruit_GFX.h"
- #include ".\Adafruit_SSD1306.h"
- // software SPI works on Maple Mini ARM 32-bit
- // use these settings for the OLED display...
- // These pin #'s are for Maple Mini/UNO/Nano/Mini328
- // __Signal__Maple_//__OLED 128x64___
- #define OLED_DC 22 // D/C 6
- #define OLED_RST 21 // RST 5
- #define OLED_MOSI 20 // SDA 4
- #define OLED_CLK 19 // SCL 3
- #define OLED_CS 14 // --- x Not Connected
- Adafruit_SSD1306 OLED(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);
- int nFrames = 36;
- void setup() {
- pinMode(17, OUTPUT);
- pinMode(18, OUTPUT);
- digitalWrite(17, LOW);
- digitalWrite(18, HIGH);
- // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
- OLED.begin(SSD1306_SWITCHCAPVCC);
- // init done
-
- // Show image buffer on the display hardware.
- // Since the buffer is intialized with an Adafruit splashscreen
- // internally, this will display the splashscreen.
- // NOTE: You _must_ call display after making any drawing commands
- // to make them visible on the display hardware!
- OLED.display(); // Adafruit Splash
- OLED.clearDisplay(); // Clear the buffer.
- // Y = 15 is the Blank Line between yellow / blue
- }
- void loop() {
- for (int frame=0; frame < nFrames; frame++)
- {
- HariChord(frame);
- }
- for (int frame=(nFrames-1); frame >= 0; frame--)
- {
- HariChord(frame);
- }
- }
- void HariChord(int frame)
- {
- OLED.clearDisplay();
- int n = 7;
- int r = frame * 64 / nFrames;
- float rot = frame * 2*PI / nFrames;
- for (int i=0; i<(n-1); i++)
- {
- float a = rot + i * 2*PI / n;
- int x1 = 64 + cos(a) * r;
- int y1 = 32 + sin(a) * r;
- for (int j=i+1; j<n; j++)
- {
- a = rot + j * 2*PI / n;
- int x2 = 64 + cos(a) * r;
- int y2 = 32 + sin(a) * r;
- OLED.drawLine(x1,y1, x2,y2, WHITE);
- }
- }
- OLED.display();
- }
复制代码 运行结果:
包括库与例程的压缩文件:
SSD1306-HariChord_swSPI.zip
(15.93 KB, 下载次数: 28)
|
|