Flashing the onboard LEDs on a PyBoard

The Pyboard comes with 4 on board LEDs, in this example we will flash them on and off, the example was written in uPyCraft

 

Pinouts

 

Parts List

Name Link
Elecrow PyBoard Elecrow Core Board For MicroPython Crow Pyboard Development Board STM32F405RG for Pyboard Python Learning Module Microcontroller

Code

First of all the various methods from the official docs

LED.intensity([value])
Get or set the LED intensity. Intensity ranges between 0 (off) and 255 (full on). If no argument is given, return the LED intensity. If an argument is given, set the LED intensity and return None.

Note: Only LED(3) and LED(4) can have a smoothly varying intensity, and they use timer PWM to implement it. LED(3) uses Timer(2) and LED(4) uses Timer(3). These timers are only configured for PWM if the intensity of the relevant LED is set to a value between 1 and 254. Otherwise the timers are free for general purpose use.

LED.off()
Turn the LED off.
LED.on()
Turn the LED on, to maximum intensity.
LED.toggle()
Toggle the LED between on (maximum intensity) and off. If the LED is at non-zero intensity then it is considered “on” and toggle will turn it off.

Now for the example showing this

from pyb import LED
import time
 
led1 = LED(1) # 1=red, 2=green, 3=yellow, 4=blue
led1.toggle()
led1.on()
time.sleep(1)
led1.off()
time.sleep(1)
 
led2 = LED(2) # 1=red, 2=green, 3=yellow, 4=blue
led2.toggle()
led2.on()
time.sleep(1)
led2.off()
time.sleep(1)
 
led3 = LED(3) # 1=red, 2=green, 3=yellow, 4=blue
led3.toggle()
led3.on()
time.sleep(1)
led3.off()
time.sleep(1)
 
led4 = LED(4) # 1=red, 2=green, 3=yellow, 4=blue
led4.toggle()
led4.on()
time.sleep(1)
led4.off()
time.sleep(1)
 
# LEDs 3 and 4 support PWM intensity (0-255)
LED(4).intensity()    # get intensity
LED(4).intensity(25) # set intensity to 25
Share

Pyboard Micropython I2C Scanner

This is a simple very short code example in which we show how to create a basic I2CScanner in Micropython using the uPyCraft IDE for a Pyboard

The arduino equivalent is one that I use frequently and is one of the most useful sketches for figuring out why a sensor may not be working correctly with a library or code – usually because the default I2C address differs from the sensor address that you buy

Layout

An example connecting a sensor to a Pyboard

 

Code

from pyb import I2C
 
i2c = I2C(1, I2C.MASTER, baudrate=100000)
print('Scan i2c bus...')
devices = i2c.scan()
 
if len(devices) == 0:
  print("No i2c device !")
else:
  print('i2c devices found:',len(devices))
 
for device in devices:  
  print("Decimal address: ",device)
  print("Hex address: ",hex(device))

 

 

Output

All going well you should output like the following in uPyCraft – this is a TMP175 connected to a PyBoard (not a BMP180 as the layout earlier)

Ready to download this file,please wait!

download ok
exec(open(‘i2cscanner.py’).read(),globals())
Scan i2c bus…
i2c devices found: 1
Decimal address: 55
Hex address: 0x37
>>>

Share

A look at the STM32F4DISCOVERY with an Arduino based example

In this example we look at the STM32F4DISCOVERY and in particular the STM32F407G-DISC1

Lets look at some key features

The STM32F4DISCOVERY kit leverages the capabilities of the STM32F407 high performance microcontrollers, to allow users to easily develop applications featuring audio.

It includes an ST-LINK embedded debug tool, one ST-MEMS digital accelerometer, a digital microphone, one audio DAC with integrated class D speaker driver, LEDs, push-buttons and an USB OTG micro-AB connector.

With the latest board enhancement, the new order code STM32F407G-DISC1 has replaced the old reference STM32F4DISCOVERY.

Key Features

  • STM32F407VGT6 microcontroller featuring 32-bit ARM®Cortex®-M4 with FPU core, 1-Mbyte Flash memory, 192-Kbyte RAM in an LQFP100 package
  • On-board ST-LINK/V2 on STM32F4DISCOVERY (old reference) or ST-LINK/V2-A on STM32F407G-DISC1 (new order code)
  • USB ST-LINK with re-enumeration capability and three different interfaces:
    • Debug port
    • Virtual Com port (with new order code only)
    • Mass storage (with new order code only)
  • Board power supply: through USB bus or from an external 5 V supply voltage
  • External application power supply: 3 V and 5 V
  • LIS302DL or LIS3DSH ST MEMS 3-axis accelerometer
  • MP45DT02 ST-MEMS audio sensor omni-directional digital microphone
  • CS43L22 audio DAC with integrated class D speaker driver
  • Eight LEDs:
    • LD1 (red/green) for USB communication
    • LD2 (red) for 3.3 V power on
    • Four user LEDs, LD3 (orange), LD4 (green), LD5 (red) and LD6 (blue)
    • 2 USB OTG LEDs LD7 (green) VBUS and LD8 (red) over-current
  • Two push-buttons (user and reset)
  • USB OTG FS with micro-AB connector
  • Extension header for all LQFP100 I/Os for quick connection to prototyping board and easy probing
  • Comprehensive free software including a variety of examples, part of STM32CubeF4 package or STSW-STM32068 to use legacy standard libraries.

 

There are 4 coloured LEDs on the STM32F407G-DISC1 development board as stated above, these are locate dunder the microcontroller

PIN NAME COLOUR POSITION
PD13 LD3 ORANGE UP
PD14 LD5 RED RIGHT
PD15 LD6 BLUE DOWN
PD12 LD4 GREEN LEFT

 

Parts List

STM32F4DISCOVERY Embeded ST-LINK/V2 STM32 Evaluation Development Board,Free shipping

Code

We used Atom IDE with Platform.IO installed and added support for the STM32 boards. This is an Arduino example (confused). You could add STM32 support to the Arduino IDE by adding stm32duino support but I like the look of Platform IDE so wanted to play about with the IDE

This is a fairly basic example to flash the LEDS off and on repeatedly

#include <Arduino.h>
 
void setup() {
  // put your setup code here, to run once:
 
  // Set the MCU's pin data direction.
  pinMode(PD13, OUTPUT);
  pinMode(PD14, OUTPUT);
  pinMode(PD15, OUTPUT);
  pinMode(PD12, OUTPUT);
 
  // Set all outputs LOW to have all LED's initially turned off.
  digitalWrite(PD13, LOW);
  digitalWrite(PD14, LOW);
  digitalWrite(PD15, LOW);
  digitalWrite(PD12, LOW);
}
 
void loop() {
  // put your main code here, to run repeatedly:
 
  // Turn off the GREEN LED, turn on the ORANGE LED and wait for 1000ms.
  digitalWrite(PD12, HIGH);
  digitalWrite(PD13, HIGH);
  digitalWrite(PD14, HIGH);
  digitalWrite(PD15, HIGH);
  delay(1000);
 
  digitalWrite(PD12, LOW);
  digitalWrite(PD13, LOW);
  digitalWrite(PD14, LOW);
  digitalWrite(PD15, LOW);
  delay(1000);
 
  // The code in the "loop()" statement will automatically repeat.
}

 

Link

https://www.st.com/en/evaluation-tools/stm32f4discovery.html

Share

A look at the Arch from Seeed

In this article we look at the Arch from Seeed. Its an MBed compatible board with Arduino headers fitted and is reasonably low cost

Features

NXP LPC11U24 MCU
Low power ARM Cortex-M0 Core
48MHz, 32KB Flash, 8KB RAM, 4KB EEPROM
USB Device, 2xSPI, UART, I2C

Here is a pinout of the Arch

 

Code

Some simple flashy LED examples that use the mbed online compiler

To program the device you do the following

The button of Arch is specially designed to provide two functions:

Quick press to reset
Long press to enter USB ISP mode, a CRP DISABLD disk will pop up.
On Windows, replace firmware.bin with your program binary file generated from the MBed compiler

Example 1

#include "mbed.h"
 
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
 
int main() {
    while(1) {
        myled1 = 1;
        wait(0.2);
        myled1 = 0;
        wait(0.2);
        myled2 = 1;
        wait(0.5);
        myled2 = 0;
        wait(0.2);
        myled3 = 1;
        wait(0.7);
        myled3 = 0;
        wait(0.2);
        myled4 = 1;
        wait(0.9);
        myled4 = 0;
        wait(0.2);
    }
}

 

Example 2

#include "mbed.h"
 
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
 
int main() {
    while(1) {
        myled1 = 1;
        myled2 = 1;
        myled3 = 1;
        myled4 = 1;
        wait(0.5);
        myled1 = 0;
        myled2 = 0;
        myled3 = 0;
        myled4 = 0;
        wait(0.5);
 
    }
}

 

We will use this for MBed examples

Share

Arduino Due and VEML6075 sensor

Another VEML sensor, this time its a VEML6075 and again we connect it to an Arduino Due

The VEML6075 senses UVA and UVB light and incorporates photodiode, amplifiers, and analog / digital circuits into a single chip using a CMOS process. When the UV sensor is applied, it is able to detect UVA and UVB intensity to provide a measure of the signal strength as well as allowing for UVI measurement.

The VEML6075 provides excellent temperature compensation capability for keeping the output stable under changing temperature. VEML6075’s functionality is easily operated via the simple command format of I2C (SMBus compatible) interface protocol. VEML6075’s operating voltage ranges from 1.7 V to 3.6 V.

 

Parts List

Amount Part Type
1 VEML6075
1 Compatible DUE R3 Board SAM3X8E 32-bit ARM Cortex-M3

 

Layout

 

arduino due and VEML6075 layout

arduino due and VEML6075 layout

 

Code

Again we use a library and again its an adafruit one

This is the full example

#include <Wire.h>
#include "Adafruit_VEML6075.h"
 
Adafruit_VEML6075 uv = Adafruit_VEML6075();
 
void setup() {
  Serial.begin(115200);
  Serial.println("VEML6075 Full Test");
  if (! uv.begin()) {
    Serial.println("Failed to communicate with VEML6075 sensor, check wiring?");
  }
  Serial.println("Found VEML6075 sensor");
 
  // Set the integration constant
  uv.setIntegrationTime(VEML6075_100MS);
  // Get the integration constant and print it!
  Serial.print("Integration time set to ");
  switch (uv.getIntegrationTime()) {
    case VEML6075_50MS: Serial.print("50"); break;
    case VEML6075_100MS: Serial.print("100"); break;
    case VEML6075_200MS: Serial.print("200"); break;
    case VEML6075_400MS: Serial.print("400"); break;
    case VEML6075_800MS: Serial.print("800"); break;
  }
  Serial.println("ms");
 
  // Set the high dynamic mode
  uv.setHighDynamic(false);
  // Get the mode
  if (uv.getHighDynamic()) {
    Serial.println("High dynamic reading mode");
  } else {
    Serial.println("Normal dynamic reading mode");
  }
 
  // Set the mode
  uv.setForcedMode(false);
  // Get the mode
  if (uv.getForcedMode()) {
    Serial.println("Forced reading mode");
  } else {
    Serial.println("Continuous reading mode");
  }
 
  // Set the calibration coefficients
  uv.setCoefficients(2.22, 1.33,  // UVA_A and UVA_B coefficients
                     2.95, 1.74,  // UVB_C and UVB_D coefficients
                     0.001461, 0.002591); // UVA and UVB responses
}
 
 
void loop() {
  Serial.print("Raw UVA reading:  "); Serial.println(uv.readUVA());
  Serial.print("Raw UVB reading:  "); Serial.println(uv.readUVB());
  Serial.print("UV Index reading: "); Serial.println(uv.readUVI());
 
  delay(1000);
}

 

Output

Open the serial monitor – this is what I saw but I tested this indoors

VEML6075 Full Test
Failed to communicate with VEML6075 sensor, check wiring?
Found VEML6075 sensor
Integration time set to 50ms
Normal dynamic reading mode
Continuous reading mode
Raw UVA reading: 0.00
Raw UVB reading: 0.00
UV Index reading: 0.00
Raw UVA reading: 0.00
Raw UVB reading: 0.00
UV Index reading: 0.00

Links

https://www.vishay.com/docs/84304/veml6075.pdf

I2C Interface 3.3V Board Based on VEML6075 UVA UVB Light Sensor Module

Share