Difference between revisions of "Mbits"

From Elecrow
Jump to navigation Jump to search
Line 65: Line 65:
 
① Letscode Mode
 
① Letscode Mode
  
[[File:Mbits-3-Axis Digital Accelerometer 1.png ||400px]]
+
[[File:Mbits-3-Axis Digital Accelerometer 1.png ||700px]]
  
 
② Code Mode
 
② Code Mode
Line 95: Line 95:
 
3.After the upload is successful,You can observe the data through the serial monitor.
 
3.After the upload is successful,You can observe the data through the serial monitor.
  
[[File:Mbits-3-Axis Digital Accelerometer 2.png ||400px]]
+
[[File:Mbits-3-Axis Digital Accelerometer 2.png ||700px]]
  
 
=='''Use on Arduino'''==
 
=='''Use on Arduino'''==

Revision as of 17:02, 7 June 2021

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: MIB26580B

Mbits 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

The definition edge connector

Edge connector definition.jpg


Use on Letscode

Install the Letscode

Part 1: Setting up the programming environment

1:Download the Letscode installation package and install it on your computer.

2:After successful installation, open the Letscode software, click "Add Extension" in the lower left corner, find the "Mbits" board type and select.

Mbits (5).png Mbits (6).png

3:Enter the programming interface, you can drag the programming block to program, when the program is written, click the "port" in the upper left corner to select the port of the Mbits board;

Mbits (7).png

4:Click the "Upload Code" button in the upper right corner, upload the code, and wait for the upload to succeed.

Part 2: Some examples

1.MPU6050 example

The reference code is as follows:

Mbits (8).png

After the code is uploaded successfully, the coordinate value of X will be displayed on the RGB dot matrix screen;


Use with Mbits-3-Axis Digital Accelerometer

Description

This is a high resolution digital accelerometer on Mbits. The module agile enough to detect single and double taps. It's ideal for motion detection, Gesture detection as well as robotics.


'Usage

Here we show how to read the raw data from the accelerometer.

1.Connect the data cable to the communication port of Mbits.

2.Open the software and upload the following program to Mbits.

① Letscode Mode

Mbits-3-Axis Digital Accelerometer 1.png

② Code Mode

// Language ArduinoC
#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);


void setup() {
  Serial.begin(115200);
  Wire.begin(22,21);
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);
}

void loop() {
  mpu6050.update();
  Serial.println(String("x的值:") + String((mpu6050.getAccX())));
  Serial.println(String("y的值:") + String((mpu6050.getAccY())));
  Serial.println(String("z的值:") + String((mpu6050.getAccZ())));
  delay(1000);
}

3.After the upload is successful,You can observe the data through the serial monitor.

Mbits-3-Axis Digital Accelerometer 2.png

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.

Mbits (10).png


  • 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);
  }
}


c)After the program is downloaded, press the Button A, the RGB dot matrix will scroll the words "WELCOME", and press the Button B to scroll the words "ELECROW";;

Mbits (2).png Mbits (3).png


2.Temperature sensor

d)Copy the library files of TMP75 to the libraries directory under the Arduino installation directory;

e)Click "File→Examples→TMP75→simpleTMP75.ino" to open the corresponding program file and download it to the Mbits board;

f)The sample code is as follows::

#include<Wire.h>
#include <tmp75.h>

#define T_LOW 24.8
#define T_HIGH 25.0125

TMP75 mySensor; // mySensor at default i2c address

void setup(){
  Wire.begin(22,21); // initialize i2c library
  Serial.begin(9600);
  int error=mySensor.begin();
  if (error) {
    Serial.println("TMP75 not responding...");
    while(1);
  }
 // ALERT pin should be low if temperature is above T_HIGH
 // and should return to high when temperature is below T_LOW
 mySensor.setHighLimit(T_HIGH);
 mySensor.setLowLimit(T_LOW);
  
}

void loop(){
  float temp = mySensor.readTemperature();
  Serial.print("Temp = ");
  Serial.print(temp,4); // 4 decimals to see full 12 bits resolution
  Serial.println(" Celsius");
  delay(500);
  
}

g)After the program is downloaded, open the serial port monitor, set the baud rate to 9600, and the serial port will print out the currently detected temperature value estimate, as shown in the figure:

Mbits (4).png

3.Buzzer

The passive buzzer is connected to the GPIO33 pin by default, and we can output PWM waves on this pin to drive the buzzer.

The following code is an example of playing a song:

int speakerPin = 33; 

int length = 15; // the number of notes 
char notes[] = "ccggaagffeeddc "; // a space represents a rest 
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; 
int tempo = 300; 

void playTone(int tone, int duration) { 
  for (long i = 0; i < duration * 1000L; i += tone * 2) { 
    digitalWrite(speakerPin, HIGH); 
    delayMicroseconds(tone); 
    digitalWrite(speakerPin, LOW); 
    delayMicroseconds(tone); 
  } 
} 

void playNote(char note, int duration) { 
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; 
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; 

  // play the tone corresponding to the note name 
  for (int i = 0; i < 8; i++) { 
    if (names[i] == note) { 
      playTone(tones[i], duration); 
    } 
  } 
} 

void setup() { 
  pinMode(speakerPin, OUTPUT); 
} 

void loop() { 
  for (int i = 0; i < length; i++) { 
    if (notes[i] == ' ') { 
      delay(beats[i] * tempo); // rest 
    } else { 
      playNote(notes[i], beats[i] * tempo); 
    } 

    // pause between notes 
    delay(tempo / 2);  
  } 
}

g)After the program is downloaded, open the serial port monitor, set the baud rate to 9600, and the serial port will print out the currently detected temperature value estimate, as shown in the figure:

After the program is downloaded successfully, you can hear the beautiful tune.


Please feel free to ask questions here. https://forum.elecrow.com/discussions