Tutorial #2: Maixduino LCD & Camera
Tutorial #2: Maixduino LCD & Camera
In this second tutorial, we are going to explore the display and camera of the Maixduino. The documentation is scarce and the examples even worse, but we are going to make it or break it.
What Will We Need
- The Maixduino Board
- The Camera
- The LCD
- 3D Printed case (Optional), link to Thingiverse here.
Usually, we receive the kit with the camera already connected. When we install them, we must make sure that the camera is facing downward and the LCD is facing upward. Also, the Camera and the LCD come with a plastic protection, so it is up to you to remove it.
Maixduino ST7789 Display Test Code
Now, we go to File->Examples->Sipeed_ST7789, compile and transfer the code to the Maixduino. The objective would be to have the display show text, geometric forms, and simple rotation.
#include <Sipeed_ST7789.h> SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD Sipeed_ST7789 lcd(320, 240, spi_); void func() { lcd.fillScreen(COLOR_RED); lcd.drawRect(20, 20, 50, 50, COLOR_WHITE); lcd.fillCircle(100, 100, 40, COLOR_WHITE); lcd.fillTriangle(10, 200, 300, 200, 300, 150, COLOR_WHITE); lcd.setTextSize(2); lcd.setTextColor(COLOR_WHITE); lcd.setCursor(100, 30); lcd.println("hello Sipeed Maix"); } void func2() { lcd.fillScreen(COLOR_RED); lcd.drawRect(20, 20, 50, 50, COLOR_WHITE); lcd.fillCircle(180, 50, 40, COLOR_WHITE); lcd.fillTriangle(10, 300, 200, 300, 200, 150, COLOR_WHITE); lcd.setTextSize(2); lcd.setTextColor(COLOR_WHITE); lcd.setCursor(1, 100); lcd.println("hello Sipeed Maix"); } void setup() { lcd.begin(15000000, COLOR_RED); } void loop() { lcd.setRotation(0); func(); delay(3000); lcd.invertDisplay(true); func(); delay(3000); lcd.setRotation(1); func2(); delay(3000); lcd.setRotation(2); func(); delay(3000); lcd.setRotation(3); func2(); delay(3000); }
If when we are compiling it gives an error, it is probably a conflict between installed libraries. Normally it is the duplicate Adafruit_GFX Library, we have to delete it from the Arduino libraries folder and then try again.
Maixduino Camera Configuration
The camera is another problem. From my research, I found out that the Sipeed_OV2640.h library doesn’t work. We have to install another and it will be OK. We have to go to Github and download the Maixduino_GC0328 library here. Then, we have to open it and move it to the Arduino library directory.
Maixduino Camera Test Code
Now, we have to open the code example File->Examples->Sipeed_OV2640 and make some changes. We have to change the Sipeed_OV2640 for the Maixduino_GC0328 and everything will be set. If everything goes as planned, we should be able to see the camera transmitted image on the display.
#include <Maixduino_GC0328.h> #include <Sipeed_ST7789.h> SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD Sipeed_ST7789 lcd(320, 240, spi_); Maixduino_GC0328 camera(FRAMESIZE_QVGA, PIXFORMAT_RGB565); void setup() { Serial.begin(115200); lcd.begin(15000000, COLOR_RED); if (!camera.begin()) Serial.printf("camera init fail\n"); else Serial.printf("camera init success\n"); camera.run(true); } void loop() { uint8_t* img = camera.snapshot(); if (img == nullptr || img == 0) Serial.printf("snap fail\n"); else lcd.drawImage(0, 0, camera.width(), camera.height(), (uint16_t*)img); }
Conclusion
At the end of the tutorial, we are now able to use the camera and display of the Maixduino and apply the knowledge to future projects.
1 comment