Skip to content
Snippets Groups Projects
Commit e7ff2abd authored by Adrián Torres's avatar Adrián Torres
Browse files

update_new_sensors_xiao

parent fec9384a
No related branches found
No related tags found
No related merge requests found
Pipeline #370499 passed
//Fab Academy 2020 - Fab Lab León
//Phototransistor
//Adrianino
//ATtiny1614
import processing.serial.*;
float sensorValue; //variable for the serial data
Serial myPort;
void setup() { //as dynamic/setup function called initially, only once
size(1024, 200);// is the window (1024=sensor max. value)
//replace the port String with the port where your Arduino is connected
//myPort = new Serial(this, "/dev/tty.wchusbserial1450", 115200);
myPort = new Serial(this, "COM3", 115200); // serial port
background(255); //set background white
}
void draw() { //draw function loops
noStroke(); // outline
fill(255,0,0,20); // color inside
rect(0, 0, sensorValue, height); //position and size
fill(255,70);
rect(sensorValue, 0, width-sensorValue, height);
println(sensorValue);
fill(0,0,0);// these are the colors inside
text(sensorValue + " " + "lux" , sensorValue, height/2);
textSize(32);
}
void serialEvent(Serial myPort) { // sketch read the serial data
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
float[] values = float(split(inString, ","));
if (values.length >=1) {
sensorValue = values[0]; //first value in the list
}
}
}
import processing.serial.*;
float sensorValue; //variable for the serial data
Serial myPort;
void setup() { //as dynamic/setup function called initially, only once
size(1024, 200);// is the window (1024=sensor max. value)
myPort = new Serial(this, "COM3", 115200); // serial port
background(255); //set background white
}
void draw() { //draw function loops
noStroke(); // outline
fill(255,0,0,20); // color inside
rect(0, 0, sensorValue, height); //position and size
fill(255,70);
rect(sensorValue, 0, width-sensorValue, height);
println(sensorValue);
fill(0,0,0);// these are the colors inside
text(sensorValue + " " + "mm" , sensorValue, height/2);
textSize(32);
}
void serialEvent(Serial myPort) { // sketch read the serial data
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
float[] values = float(split(inString, ","));
if (values.length >=1) {
sensorValue = values[0]; //first value in the list
}
}
}
//Fab Academy 2023 - Fab Lab León
//Hall effect
//Fab-Xiao
int sensorPin = 26; // analog input pin to hook the sensor to
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(115200); // initialize serial communications
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor
sensorValue = map(sensorValue, 200, 800, 1024, 0);
Serial.println(sensorValue); // print value to Serial Monitor
//mySerial.println("x"); // print value "x" to Serial Monitor
delay(50); // short delay so we can actually see the numbers
}
//Fab Academy 2023 - Fab Lab León
//Fab-Xiao
int sensorPin = 26; // analog input pin to hook the sensor to
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(115200); // initialize serial communications
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor
sensorValue = map(sensorValue, 482, 890, 19, 180);
Serial.println(sensorValue); // print value to Serial Monitor
//mySerial.println("x"); // print value "x" to Serial Monitor
delay(500); // short delay so we can actually see the numbers
}
/******************************************************************************
QRD1114_Proximity_Example.ino
Example sketch for SparkFun's QRD1114 Reflectance Proximity Sensor
(https://www.sparkfun.com/products/246)
Jim Lindblom @ SparkFun Electronics
May 2, 2016
Modified by Adrián Torres Omaña
Fab Lab LeÓN
Phototransistor IR
Fab-Xiao
******************************************************************************/
const int Sensor = 26; // Sensor output voltage
void setup()
{
Serial.begin(115200);
pinMode(Sensor, INPUT);
}
void loop()
{
// Read in the ADC and convert it to a voltage:
int proximityADC = analogRead(Sensor);
float proximityV = (float)proximityADC * 1000.0 / 1023.0;
Serial.println(proximityV);
delay(100);
}
//Fab Academy 2023 - Fab Lab León
//Time of Flight VL53L1X
//Fab-Xiao
/*
This example shows how to take simple range measurements with the VL53L1X. The
range readings are in units of mm.
*/
#include <Wire.h>
#include <VL53L1X.h>
VL53L1X sensor;
void setup()
{
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1);
}
// Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
// You can change these settings to adjust the performance of the sensor, but
// the minimum timing budget is 20 ms for short distance mode and 33 ms for
// medium and long distance modes. See the VL53L1X datasheet for more
// information on range and timing limits.
sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(50000);
// Start continuous readings at a rate of one measurement every 50 ms (the
// inter-measurement period). This period should be at least as long as the
// timing budget.
sensor.startContinuous(50);
}
void loop()
{
Serial.print(sensor.read());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
...@@ -88,11 +88,15 @@ ...@@ -88,11 +88,15 @@
<li><a href="#inputs" class="button primary">Inputs</a></li> <li><a href="#inputs" class="button primary">Inputs</a></li>
<li><a href="#button" class="button">Button</a></li> <li><a href="#button" class="button">Button</a></li>
<li><a href="#photo" class="button">Phototransistor</a></li> <li><a href="#photo" class="button">Phototransistor</a></li>
<li><a href="#step" class="button">Step Response</a></li> <li><a href="#photoir" class="button">Phototransistor IR</a></li></ul>
</ul>
<ul class="actions">
<li><a href="#step" class="button">Step Response</a></li>
<li><a href="#flight2" class="button">Time of flight VL53L1X</a></li>
<li><a href="#hall" class="button">Hall effect</a></li>
<li><a href="#temperature" class="button">Temperature</a></li></ul>
<ul class="actions"> <ul class="actions">
<li><a href="#outputs" class="button primary">Outputs</a></li> <li><a href="#outputs" class="button primary">Outputs</a></li>
...@@ -409,6 +413,65 @@ void loop() { ...@@ -409,6 +413,65 @@ void loop() {
<p><video controls width="100%"; max-width="800"><source src="images/fabxiao/photo.mp4" type="video/mp4"></video></p> <p><video controls width="100%"; max-width="800"><source src="images/fabxiao/photo.mp4" type="video/mp4"></video></p>
<h2><a id="photoir"></a>Phototransistor. IR.</h2>
<p>The <a href="https://www.digikey.com/product-detail/en/everlight-electronics-co-ltd/PT15-21B-TR8/1080-1379-1-ND"><b>Phototransistor IR</b></a> sensor is a three-layer semiconductor device which has a light-sensitive base region. The base senses the IR and converts it into the current which flows between the collector and the emitter region.</p>
<li><b>Connection and schematic</b></li>
<p>In this case, being a component without a module, I create my own. I design and manufacture a small board where I solder the Phototransistor IR sensor, a 10K resistor, a <a href="https://www.digikey.es/product-detail/es/everlight-electronics-co-ltd/IR15-21C-TR8/1080-1352-1-ND/2676086"><b>IR LED,</b></a> a 1K resistor and with the flat connectors where there is no room for mistakes when connecting it. I use the analog input of the Seeed XIAO RP2040 GPIO 26 (Arduino pin 26).</p>
<span class="image main"><img src="images/adrianino/a_22.jpg" alt="" /></span>
<p>Here you can find the design in Eagle and the PNG's to create the board.</p>
<p><a href="assignments/adrianino/phototransisor_IR_eagle.zip"><b>- Phototransistor IR Schematic + Board</b></a>
<p><a href="assignments/adrianino/photo_ir_png.zip"><b>- Phototransistor IR traces and interior</b></a></p>
<p><img src="images/adrianino/a_23.jpg" width="50%"; max-width="700" /></p>
<li><b>Programming</b></li>
<p>Here you will find the programming to use an analog sensor such as the Phototransistor sensor. Here you can find the Arduino and Processing files to download. Below you can see a video of how it works.</p>
<p><a href="assignments/fabxiao/xiao_photo_ir/xiao_photo_ir.ino"><b>- Arduino Hello Phototransistor IR sensor</b></a>
<p><a href="assignments/fabxiao/phototransitor_processing_ir/phototransitor_processing_ir.pde"><b>- Processing Hello Phototransistor IR sensor</b></a></p>
<pre><code>/******************************************************************************
QRD1114_Proximity_Example.ino
Example sketch for SparkFun's QRD1114 Reflectance Proximity Sensor
(https://www.sparkfun.com/products/246)
Jim Lindblom @ SparkFun Electronics
May 2, 2016
Modified by Adrián Torres Omaña
Fab Lab LeÓN
Phototransistor IR
Fab-Xiao
******************************************************************************/
const int Sensor = 26; // Sensor output voltage
void setup()
{
Serial.begin(115200);
pinMode(Sensor, INPUT);
}
void loop()
{
// Read in the ADC and convert it to a voltage:
int proximityADC = analogRead(Sensor);
float proximityV = (float)proximityADC * 1000.0 / 1023.0;
Serial.println(proximityV);
delay(100);
}</code></pre>
<p><video controls width="100%"; max-width="800"><source src="images/adrianino/photo_ir.mp4" type="video/mp4"></video></p>
<h2><a id="step"></a>Step Response.</h2> <h2><a id="step"></a>Step Response.</h2>
...@@ -506,6 +569,170 @@ delay(100); ...@@ -506,6 +569,170 @@ delay(100);
<h2><a id="flight2"></a>Time of flight VL53L1X</h2>
<p>I use a module that integrates the <b>VL53L1X sensor.</b> The module is sold by <a href="https://www.pololu.com/product/3415"> <b>Polulu,</b></a> although in my case I bought it from <a href="https://www.amazon.es/ACAMPTAR-Vl53L1X-M%C3%B3Dulo-Sensor-Tiempo/dp/B08TBZL5Q3/ref=sr_1_11?__mk_es_ES=%C3%85M%C3%85%C5%BD%C3%95%C3%91&dchild=1&keywords=VL53L1X&qid=1614460990&s=electronics&sr=1-11"> <b>Amazon.</b></a>
In this case of the pinout that the sensor brings, I will only use the VCC, GND, SDA and SCL pins.</p>
<p><img src="images/adrianino/a_34.jpg" width="70%"; max-width="700" /></p>
<li><b>Connection and schematic</b></li>
<p>In this case we only need four cables; one for <b>VCC</b>, one for <b>GND</b>, another cable for the SDA and SCL, the I2C connection.</p>
<p><img src="images/adrianino/a_35.jpg" width="70%"; max-width="700" /></p>
<li><b>Programming</b></li>
<p>Here you will find the programming to use the Time of Flight VL53L1X sensor. Here you can find the Arduino and Processing files to download. Below you can see a video of how it works. <b>Recommendation:</b> Download the program from the link, in the text the symbols <b><></b> of the libraries are missing.</p>
<p><a href="assignments/fabxiao/xiao_tof_rojo/xiao_tof_rojo.ino"><b>- Arduino Time of Flight VL53L1X sensor</b></a>
<p><a href="assignments/fabxiao/time_flight_xiao/time_flight_xiao.pde"><b>- Processing Time of Flight VL53L1X sensor </b></a></p>
<pre><code>//Fab Academy 2023 - Fab Lab León
//Time of Flight VL53L1X
//Fab-Xiao
/*
This example shows how to take simple range measurements with the VL53L1X. The
range readings are in units of mm.
*/
#include <Wire.h>
#include <VL53L1X.h>
VL53L1X sensor;
void setup()
{
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1);
}
// Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
// You can change these settings to adjust the performance of the sensor, but
// the minimum timing budget is 20 ms for short distance mode and 33 ms for
// medium and long distance modes. See the VL53L1X datasheet for more
// information on range and timing limits.
sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(50000);
// Start continuous readings at a rate of one measurement every 50 ms (the
// inter-measurement period). This period should be at least as long as the
// timing budget.
sensor.startContinuous(50);
}
void loop()
{
Serial.print(sensor.read());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}</code></pre>
<p><video controls width="100%"; max-width="800"><source src="images/adrianino/vl531x.mp4" type="video/mp4"></video></p>
<h2><a id="hall"></a>Hall effect</h2>
<p>The <a href="https://www.digikey.com/product-detail/en/A1324LLHLT-T/620-1402-1-ND/"><b>Hall effect</b></a> sensor or simply Hall sensor or Hall probe uses the Hall effect to measure magnetic fields or currents or to determine the position in which it is.</p>
<li><b>Connection and schematic</b></li>
<p>In this case, being a component without a module, I create my own. I design and manufacture a small board where I solder the hall effect sensor and with the flat connectors where there is no room for mistakes when connecting it. I use the analog input of the Seeed XIAO RP2040 GPIO 26 (Arduino pin 26).</p>
<span class="image main"><img src="images/adrianino/a_09.jpg" alt="" /></span>
<p>Here you can find the design in Eagle and the PNG's to create the board.</p>
<p><a href="assignments/adrianino/hall_effect_eagle.zip"><b>- Hall effect Schematic + Board</b></a>
<p><a href="assignments/adrianino/hall_effect_png.zip"><b>- Hall effect traces and interior</b></a></p>
<p><img src="images/adrianino/a_10.jpg" width="50%"; max-width="700" /></p>
<li><b>Programming</b></li>
<p>Here you will find the programming to use an analog sensor such as the Hall effect sensor. Here you can find the Arduino and Processing files to download. Below you can see a video of how it works.</p>
<p><a href="assignments/fabxiao/xiao_hall/xiao_hall.ino"><b>- Arduino Hello Hall effect sensor</b></a>
<p><a href="assignments/adrianino/hall_effect_processing/hall_effect_processing.pde"><b>- Processing Hello Hall effect sensor</b></a></p>
<pre><code>//Fab Academy 2023 - Fab Lab León
//Hall effect
//Fab-Xiao
int sensorPin = 26; // analog input pin to hook the sensor to
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(115200); // initialize serial communications
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor
sensorValue = map(sensorValue, 200, 800, 1024, 0);
Serial.println(sensorValue); // print value to Serial Monitor
//mySerial.println("x"); // print value "x" to Serial Monitor
delay(50); // short delay so we can actually see the numbers
}</code></pre>
<p><video controls width="100%"; max-width="800"><source src="images/adrianino/hall.mp4" type="video/mp4"></video></p>
<h2><a id="temperature"></a>Temperature. NTC.</h2>
<p>The <a href="https://www.digikey.com/product-detail/en/NHQ103B375T10/235-1109-1-ND"><b>NTC</b></a> sensor is a type of resistance whose value varies as a function of temperature in a more pronounced way than a common resistance. Its operation is based on the variation of the resistivity that a semiconductor presents with temperature.</p>
<li><b>Connection and schematic</b></li>
<p>In this case, being a component without a module, I create my own. I design and manufacture a small board where I solder the NTC sensor, a 10K resistor and with the flat connectors where there is no room for mistakes when connecting it. I use the analog input of the Seeed XIAO RP2040 GPIO 26 (Arduino pin 26).</p>
<span class="image main"><img src="images/adrianino/a_12.jpg" alt="" /></span>
<p>Here you can find the design in Eagle and the PNG's to create the board.</p>
<p><a href="assignments/adrianino/temperature_eagle.zip"><b>- NTC Schematic + Board</b></a>
<p><a href="assignments/adrianino/temperature_png.zip"><b>- NTC traces and interior</b></a></p>
<p><img src="images/adrianino/a_13.jpg" width="50%"; max-width="700" /></p>
<li><b>Programming</b></li>
<p>Here you will find the programming to use an analog sensor such as the NTC sensor. Here you can find the Arduino and Processing files to download. Below you can see a video of how it works.</p>
<p><a href="assignments/fabxiao/xiao_ntc/xiao_ntc.ino"><b>- Arduino Hello NTC Temperature sensor</b></a>
<p><a href="assignments/adrianino/temperature_processing/temperature.pde"><b>- Processing Hello NTC Temperature sensor</b></a></p>
<pre><code>//Fab Academy 2023 - Fab Lab León
//Fab-Xiao
int sensorPin = 26; // analog input pin to hook the sensor to
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(115200); // initialize serial communications
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor
sensorValue = map(sensorValue, 482, 890, 19, 180);
Serial.println(sensorValue); // print value to Serial Monitor
//mySerial.println("x"); // print value "x" to Serial Monitor
delay(500); // short delay so we can actually see the numbers
}</code></pre>
<p><video controls width="100%"; max-width="800"><source src="images/adrianino/temperature.mp4" type="video/mp4"></video></p>
<h1><a id="outputs"></a>Outputs</h1> <h1><a id="outputs"></a>Outputs</h1>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment