Inputs

Assignments

-individual assignment:
-measure something: add a sensor to a microcontroller board
-that you have designed and read it
-group assignment:
-probe an input device's analog levels and digital signals

Research

Time-of-Flight sensor KiCad pico library

throughout the week

Group Work

Group Site Link This week for group work I helped make the board for the input we tested.

Time-of-Flight sensor

prototyping

we started by downloading the library for the VL53L1X and pulling up the example code for it to test it with the actual sensor. I tested it with an Arduino just so I could make sure it worked. Here is the code and video of it working.

/*
  Reading distance from the laser based VL53L1X
  By: Nathan Seidle
  SparkFun Electronics
  Date: April 4th, 2018
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  SparkFun labored with love to create this code. Feel like supporting open source hardware?
  Buy a board from SparkFun! https://www.sparkfun.com/products/14667

  This example prints the distance to an object.

  Are you getting weird readings? Be sure the vacuum tape has been removed from the sensor.
*/

#include <Wire.h>
#include "SparkFun_VL53L1X.h" //Click here to get the library: http://librarymanager/All#SparkFun_VL53L1X

//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
  Wire.begin();

  Serial.begin(115200);
  Serial.println("VL53L1X Qwiic Test");

  if (distanceSensor.begin() != 0) //Begin returns 0 on a good init
  {
    Serial.println("Sensor failed to begin. Please check wiring. Freezing...");
    while (1)
      ;
  }
  Serial.println("Sensor online!");
}

void loop(void)
{
  distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
  while (!distanceSensor.checkForDataReady())
  {
    delay(1);
  }
  int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
  distanceSensor.clearInterrupt();
  distanceSensor.stopRanging();

  Serial.print("Distance(mm): ");
  Serial.print(distance);

  float distanceInches = distance * 0.0393701;
  float distanceFeet = distanceInches / 12.0;

  Serial.print("\tDistance(ft): ");
  Serial.print(distanceFeet, 2);

  Serial.println();
}



After I made sure the sensor worked I hooked it up to the rasberry Pico rp2040 with the help of Griffin Osinger with its SCL and SDA pins attached. I then uploaded the code and it worked. Here is a video of it working.



Once I had gotten the sensor working I wanted to test it out by making Leds turn on based on how far away my hand was. So I added some LEDS and connected them to the circuit. Once I added them I added them into my code by making some if statements for how far it is and then turning on the led. Here is the full code.

#include <Wire.h>
#include "SparkFun_VL53L1X.h" //Click here to get the library: http://librarymanager/All#SparkFun_VL53L1X

//Optional interrupt and shutdown pins.
#define SHUTDOWN_PIN 2
#define INTERRUPT_PIN 3
#define ledOne 15
#define ledTwo 14
#define ledThree 13

SFEVL53L1X distanceSensor;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);

void setup(void)
{
  Wire.begin();

  Serial.begin(115200);
  Serial.println("VL53L1X Qwiic Test");

  if (distanceSensor.begin() != 0) //Begin returns 0 on a good init
  {
    Serial.println("Sensor failed to begin. Please check wiring. Freezing...");
    while (1)
      ;
  }
  Serial.println("Sensor online!");
   pinMode(ledOne, OUTPUT);
   pinMode(ledTwo, OUTPUT);
   pinMode(ledThree, OUTPUT);
}

void loop(void)
{
  distanceSensor.startRanging(); //Write configuration bytes to initiate measurement
  while (!distanceSensor.checkForDataReady())
  {
    delay(1);
  }
  int distance = distanceSensor.getDistance(); //Get the result of the measurement from the sensor
  distanceSensor.clearInterrupt();
  distanceSensor.stopRanging();
  Serial.print("Distance(mm): ");
  Serial.print(distance);
  float distanceInches = distance * 0.0393701;
  float distanceFeet = distanceInches / 12.0;
  Serial.print("\tDistance(ft): ");
  Serial.print(distanceFeet, 2);
  Serial.println();

  if(distance < 250){
    digitalWrite(ledOne, HIGH);
  }
  else{
    digitalWrite(ledOne, LOW);
  }
  if(distance < 500 && distance > 250){
    digitalWrite(ledTwo, HIGH);
  }
  else{
    digitalWrite(ledTwo, LOW);
  }
  if(distance < 750 && distance > 500){
    digitalWrite(ledThree, HIGH);
  }
  else{
    digitalWrite(ledThree, LOW);
  }
}


image


Board

After I had figured out how everything would work together all that was left was to design, mill, and put together a PCB board for it all. I started in KiCad and got the library for a raspberry pico rp 2040, and put it in the schematic with all the LEDs and resistors.
image
After I got all the pieces in place all that was left was to wire it all together and add an edge to the board which I did right here.
image
I then needed to mill the board out, so I quickly went to the bantam mill machine and cut out my board.
image
Once I milled out my board all I had left was soldering all the pieces down. I started by soldering the microcontroller the raspberry pico rp 2040 down onto to PCB.
image
I then had to solder 3 330 ohm resistors, so the LEDs did not fry.
image
The last pieces I had to solder were the LEDs and the pin headers, so I could attach the time of flight sensor to it.
image
After all of that I was done, so I just uploaded the previous code onto the board, and it worked. Here is a picture of the final result and video of it working.
image


Summary

This week I learned how to use a time of flight distance sensor which will help me truly refine the soda machine week project into my final project by making the machine be able to tell where the plate is by using it. While I was a little worried at first that it might not work with Arduino code it all worked out in the end. The next step I will make on these sensors is having two and being able to find the center of an object by putting the object in the middle of them like I plan to do on my final project.

Files

Week 11 Downloads