Mbits

From Elecrow
Jump to navigation Jump to search

Introduction

Mbits is a pocket-sized microcontroller has lots of features the same as Microbit V2. Mbits is an ESP32-WROVER-B based educational hardware suitable for kids to learn how to program and experience hot topics such as IoT and AI.

Model: RPA20901S

Binocular Stereo Vision Expansion Board for Raspberry Pi 1.jpg


Features

  • Pocket-sized microcontroller designed
  • Wireless connectivity with built-in 2.4GHz micro:bit radio and BLE Bluetooth 4.2
  • Onboard MEMS microphone, speaker, 25 RGB LEDs
  • Onboard accelerometer for motion sensing applications
  • Notched edge connector for easier connections
  • Dedicated I2C bus for peripherals
  • Two programmable buttons
  • Supports graphical programming (Lestscode, based on Scratch3.0) and Arduino IDE


Use on Arduino

  • Part 1. Setting up the programming environment

1:Download and install the latest version of Arduino IDE, Windows Installer from https://www.arduino.cc/en/software

2:Add ESP32 development board data in Arduino IDE

a)Click "File" → "Preferences" to enter the Preferences interface.

b)Add the URL https://dl.espressif.com/dl/package_esp32_index.json to "Additional Boards Manager URLs".

c)After adding the URL, you can search and download the ESP32 development board data package in: Tool→Board→Boards Manager.

d)So far, the environment has been set up.


  • Part 2: Some examples

1.5*5 RGB dot matrix and buttons

The 5*5RGB dot matrix is controlled by GPIO13, Button A is controlled by GPIO36, and Button B is controlled by GPIO39.

a)Copy the following three library files (Button, FastLED-master, RGB_Font) to the libraries under the Arduino installation directory;

b)Download the following program (RGB_Test) to the Mbits board;

 #include <FastLED.h>
 #include "Dots5x5font.h"
 #define NUM_ROWS 5
 #define NUM_COLUMNS 5
 #define NUM_LEDS (NUM_ROWS * NUM_COLUMNS)
 #define LED_PIN 13
 #define LED_TYPE WS2812B
 #define COLOR_ORDER GRB
 #include <Button.h>
 CRGBArray<NUM_LEDS> leds;
 uint8_t max_bright = 10;
 CRGB myRGBcolor_uijf(0, 255, 21);
 CRGB myRGBcolor_28dt(34, 0, 255);
 void plotMatrixChar(CRGB (*matrix)[5], CRGB myRGBcolor, int x, char character, int width, int height) {
   int y = 0;
   if (width > 0 && height > 0) {
     int charIndex = (int)character - 32;
     int xBitsToProcess = width;
     for (int i = 0; i < height; i++) {
       byte fontLine = FontData[charIndex][i];
       for (int bitCount = 0; bitCount < xBitsToProcess; bitCount++) {
         CRGB pixelColour = CRGB(0, 0, 0);
         if (fontLine & 0b10000000) {
           pixelColour = myRGBcolor;
         }
         fontLine = fontLine << 1;
         int xpos = x + bitCount;
        int ypos = y + i;
         if (xpos < 0 || xpos > 10 || ypos < 0 || ypos > 5);
         else {
           matrix[xpos][ypos] = pixelColour;
         }
       }
     }
   }
 }
 void ShowString(String sMessage,CRGB myRGBcolor) {
   CRGB matrixBackColor[10][5];
   int mapLED[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
  int messageLength = sMessage.length();
   for (int x = 0; x < messageLength; x++) {
     char myChar = sMessage[x];
     plotMatrixChar(matrixBackColor, myRGBcolor, 0 , myChar, 5, 5);
     for (int sft = 0; sft <= 5; sft++) {
       for (int x = 0; x < NUM_COLUMNS; x++) {
         for (int y = 0; y < 5; y++) {
           int stripIdx = mapLED[y * 5 + x];
           if (x + sft < 5) {
             leds[stripIdx] = matrixBackColor[x + sft][y];
           } else {
             leds[stripIdx] = CRGB(0, 0, 0);



           }
         }
       }
       FastLED.show();
       if (sft == 0) {
         FastLED.delay(200);
       } else {
         FastLED.delay(30);
       }
     }
   }
 }


 void setup() {
   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
   FastLED.setBrightness(max_bright);
 }
 void loop() {
   if (buttonA.isPressed() && !buttonB.isPressed()) {
     ShowString("welcome",myRGBcolor_uijf);
   }
   if (buttonB.isPressed() && !buttonA.isPressed()) {
     ShowString("elecrow",myRGBcolor_28dt);
   }
 }