Home CodeMBed STM32 Nucleo and Easy module shield more examples

STM32 Nucleo and Easy module shield more examples

by shedboy71

The Easy Module Shield V1 is a basic shield for the Arduino which has several useful components fitted that can be used for beginners learning, here is a list of these components

  • A DHT11 temperature and humidity sensor
  • An LM35 temperature sensor
  • A piezo buzzer
  • An RGB LED
  • A blue LED and a red LED
  • An IR receiver
  • A photoresistor
  • A rotary potentiometer
  • Two pushbuttons

 

Lets look at some more examples using this shield

Code

Button and LED example

[codesyntax lang=”cpp”]

#include "mbed.h"
 
DigitalIn button(D3);
DigitalOut myled(D12);

int main()
{
    while(1)
    {
        myled = 1; // LED is ON
        if(button)
        {
            myled = 0; // LED is ON
            wait(0.7); // simple debouncing
        }           
    }
 
}

[/codesyntax]

DHt11 and terminal out example

[codesyntax lang=”cpp”]

#include "mbed.h"
#include "DHT11.h"
 
 Serial pc(USBTX, USBRX);
 DHT11 sensor(D4);
 
 int main() 
 {
    int state;
    while(true) 
    {
     state = sensor.readData();
 
        if (state != DHT11::OK) 
        {
            pc.printf("Error: %d", state);
        } 
        else 
        {
            pc.printf("T: %dC, H: %d%%\n", sensor.readTemperature(), sensor.readHumidity());
        }
        wait(2.0);
    }
 }

[/codesyntax]

Buzzer example

[codesyntax lang=”cpp”]

#include "mbed.h"
 
DigitalOut buzzer(D5);
 
int main() {
    int on = 1, off = 0;
    
    while(1){
        buzzer = on;
        wait(.5);
        buzzer = off;
        wait(.5);
    }
}

[/codesyntax]

PWM example flashing LED D12

[codesyntax lang=”cpp”]

#include "mbed.h"
 
PwmOut led(D12);
 
int main() {
    // specify period first, then everything else
    led.period(4.0f);  // 4 second period
    led.pulsewidth(2); // 2 second pulse (on)
    while(1);          // led flashing
}

[/codesyntax]

 

Links


Keyes V1 FR4 Multi-Purpose Shield Learning Module for Arduino – Red – $7.34

from: DealExtreme


ST NUCLEO-F401RE STM32F401RE Development Board for Arduino – White + Multicolored

from: DealExtreme

Share

You may also like