Mark Ludwig
Published © CC BY-SA

Explorer Backpack for the RISC-V WCH CH32V307V

Explore your world with a variety of sensors using the RISC-V backpack add-on board. Measure temperature, humidity, light, motion and more.

AdvancedFull instructions providedOver 3 days164

Things used in this project

Hardware components

WCH Electronics CH32V307V Development Board
×1
JLCPCB Customized PCB
JLCPCB Customized PCB
×1
Accelerometer (LIS3DHTR)
STMicroelectronics
×1
Addressable LED (SK6805-EC15)
OPSCO Optoelectronics
×10
Audio Amplifier (PAM8304)
Diodes Incorporated
×1
Buzzer (FUET-7525-3.6V)
FUET
×1
IR Decoder IC (VSOP38338)
Vishay Intertech
×1
IR LED (IR17-21C/TR8)
Everlight Elec
×1
Light Sensor (ALS-PT19-315C/L177/TR8)
Everlight Elec
×1
Microphone MEMS (IM69D130V01)
Infineon Technologies
×1
Photodiode (VEMD6110X01)
Vishay Semiconductor Opto Division
×1
Temperature and Humidity (SHT31-DIS-B2.5kS)
Sensirion
×1
Tactile Switch (EVQQ2K03W)
Panasonic
×2
Tactile Switch (PTS810SJS250SMTRLFS)
C&K
×1
Slide Switch (AYZ0202AGRLC)
C&K
×1
Pin Header 1x6 2.54mm Pitch
BOOMELE (Boom Precision Elec)
×1
Pin Header 1x8 2.54mm Pitch
Nextron (Nextronics Engineering)
×2
Pin Header 1x10 2.54mm Pitch
BOOMELE (Boom Precision Elec)
×1
Logic-Level Shifter / Buffer (SN74LVC1G125DRLR)
Texas Instruments
×1
BJT (MMBT2222A)
Jiangsu Changjing Electronics Technology Co
×1
LEDs SMD 0805
1 x Green LED (C2297), 1 x Red LED (C84256)
×1
Multilayer Ceramic Capacitors SMD 0805
4 x 100nF (C28233), 1 x 220nF (C5378), 1 x 1uF (C28323)
×1
Resistors SMD 0805
2 x 510Ω (C17734), 2 x 1kΩ (C17513), 3 x 10kΩ (C17414)
×1

Software apps and online services

RT-Thread IoT OS
RT-Thread IoT OS
WCH Electronics MaunRiver Studio

Story

Read more

Custom parts and enclosures

WCH CH32V307V Dev Board Bumper Case

For extra credit I designed a 3D printed "bumper" case to protect the bottom of the board. It uses 4 - M2.5 x 8 bolts to secure the board to the case.

Schematics

Explorer Backpack Schematic

Code

Blink

C/C++
My first program using MounRiver Studio to blink the onboard LED on the Explorer Backpack on pin PA2. This uses a modified version of the GPIO Toggle example.
#include "debug.h"

/*********************************************************************
 * @fn      GPIO_Toggle_INIT
 *
 * @brief   Initializes GPIOA.2
 *
 * @return  none
 */

void GPIO_Toggle_INIT(void)
{
    GPIO_InitTypeDef GPIO_InitStructure = {0};

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
}

/*********************************************************************
 * @fn      main
 *
 * @brief   Main program.
 *
 * @return  none
 */

int main(void)
{
    u8 i = 0;

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    Delay_Init();
    USART_Printf_Init(115200);
    printf("SystemClk:%d\r\n", SystemCoreClock);

    printf("GPIO Toggle TEST\r\n");
    GPIO_Toggle_INIT();

    while(1)
    {
        Delay_Ms(500);
        GPIO_WriteBit(GPIOA, GPIO_Pin_2, (i == 0) ? (i = Bit_SET) : (i = Bit_RESET));
    }
}

Addressable LEDs

C/C++
Testing the addressable LEDs on the Explorer Backpack using the Arduino IDE and the Adafruit Neopixel library on an Arduino Uno. This uses a modified version of the strandtest example sketch.
#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
#define LED_PIN    9

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 10

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)


// setup runs once at startup
void setup() {
  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}

// loop runs repeatedly as long as board is on
void loop() {
  rainbow(10);             // Flowing rainbow cycle along the whole strip
}

// Some functions of our own for creating animated effects

// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we'll make 5*65536/256 = 1280 passes through this loop:
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    // strip.rainbow() can take a single argument (first pixel hue) or
    // optionally a few extras: number of rainbow repetitions (default 1),
    // saturation and value (brightness) (both 0-255, similar to the
    // ColorHSV() function, default 255), and a true/false flag for whether
    // to apply gamma correction to provide 'truer' colors (default true).
    strip.rainbow(firstPixelHue);
    // Above line is equivalent to:
    // strip.rainbow(firstPixelHue, 1, 255, 255, true);
    strip.show(); // Update strip with new contents
    delay(wait);  // Pause for a moment
  }
}

Audio Out

C/C++
Testing the speaker on the Explorer Backpack using the Arduino IDE on an Arduino Uno. This uses a modified version of the code provided in the resource link at the top of the sketch.
// Resource:
// https://create.arduino.cc/projecthub/SURYATEJA/use-a-buzzer-module-piezo-speaker-using-arduino-uno-89df45

// The Arduino pin connected to the AUDIO IN on the amplifier (PAM8304)
const int buzzer = A1;

// The Arduino pin connected to the ENABLE pin on the amp
const int enable = 8;

void setup(){
  // Set both pins to outputs
  pinMode(buzzer, OUTPUT);
  pinMode(enable, OUTPUT);

  // Turn on the enable pin
  digitalWrite(enable, HIGH);
}

void loop(){
  tone(buzzer, 262);  // Middle C in hertz
  delay(500);         // Delay for 500 ms
  tone(buzzer, 294);  // D in hertz
  delay(500);         // Delay for 500 ms
  tone(buzzer, 330);  // E in hertz
  delay(500);         // Delay for 500 ms
  tone(buzzer, 349);  // F in hertz
  delay(500);         // Delay for 500 ms
  tone(buzzer, 392);  // G in hertz
  delay(500);         // Delay for 500 ms
  tone(buzzer, 440);  // A in hertz
  delay(500);         // Delay for 500 ms
  tone(buzzer, 493);  // B in hertz
  delay(500);         // Delay for 500 ms
  tone(buzzer, 523);  // C in hertz
  delay(500);         // Delay for 500 ms
  noTone(buzzer);     // Stop the sound...
  delay(5000);        // ...for 5 sec
}

Light Sensor

C/C++
Testing the ambient light sensor on the Explorer Backpack using the Arduino IDE on an Arduino Uno. This uses a modified version of the AnalogInOutSerial example sketch. The value is sent to the Serial Monitor.
// The pin the light sensor is attached to
const int analogInPin = A0;

// Set up the variable for the light sensor value
int sensorValue = 0;

void setup() {
  // initialize serial communications at 9600 baud
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);

  // print the results to the Serial Monitor:
  Serial.print("Light = ");
  Serial.println(sensorValue);

  // wait 1000 milliseconds before the next loop for the analog-to-digital
  delay(1000);
}

Buttons

Python
Testing the left and right buttons (momentary switches) on the Explorer Backpack using Circuit Python with a Raspberry Pi Pico. The value is sent to the serial monitor and turns on the onboard LED.
import time
import board
import digitalio

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

leftButton = digitalio.DigitalInOut(board.GP13)
leftButton.switch_to_input(pull=digitalio.Pull.DOWN)

rightButton = digitalio.DigitalInOut(board.GP12)
rightButton.switch_to_input(pull=digitalio.Pull.DOWN)

while True:
    if leftButton.value:
        print("Left button pressed")
        led.value = True
    if rightButton.value:
        print("Right button pressed")
        led.value = True
    time.sleep(0.1)
    led.value = False

GitHub Repository

Link to my GitHub Repository. It contains the source files for the 3D Printed Case, PCB Assembly, Bill of Materials, Board Previews, EasyEDA files, Gerbers, Photos, Pinout Diagram and Schematic.

Credits

Mark Ludwig

Mark Ludwig

1 project • 4 followers
I’m a part-time maker. My hobbies include computers and 3D printing. Recently I’ve been learning about electronics and PCB design.

Comments