Week 11 Input devices

Group assignment

probe an input device's analog levels and digital signals
Group site

Individual assignment

measure something: add a sensor to a microcontroller board that you have designed and read it

Result / Hero shot

• I measured something by step response, traced by serial plotter.

Making the sensor

• In Fab academy 2023, heard about sensor used "step response" several times. It sounded interesting because it merely 2 sheets of copper, but measure many things.

• Prepared a board for step response
• Prepared copper tape and created 2 electrodes. We made 50 x 100 mm electrodes, thickness is 0.03mm.

### Program referred
• I referred Adrian's site and copied programs. Then modified it for xiao 2040.
``````//tx_rx03  Robert Hart Mar 2019.
//https://roberthart56.github.io/SCFAB/SC_lab/Sensors/tx_rx_sensors/index.html

//Step Response TX, RX
//ATtiny1614

//Modified by Shin Masuoka
//Step Response TX, RX
//xiao rp 2040

//  Program to use transmit-receive across space between two conductors.
//  One conductor attached to digital pin, another to analog pin.
//
//  This program has a function "tx_rx() which returns the value in a long integer.
//
//  Optionally, two resistors (1 MOhm or greater) can be placed between 5V and GND, with
//  the signal connected between them so that the steady-state voltage is 2.5 Volts.
//
//  Signal varies with electric field coupling between conductors, and can
//  be used to measure many things related to position, overlap, and intervening material
//  between the two conductors.
//

long result;   //variable for the result of the tx_rx measurement.
int analog_pin = 26; //  Analog pin of xiao rp 2040
int tx_pin = 0;  //     TX pin of xiao rp 2040
void setup() {
pinMode(tx_pin,OUTPUT);      //Pin 2 provides the voltage step
Serial.begin(115200);
}

long tx_rx(){         //Function to execute rx_tx algorithm and return a value
//that depends on coupling of two electrodes.
//Value returned is a long integer.
int diff;
long int sum;
int N_samples = 100;    //Number of samples to take.  Larger number slows it down, but reduces scatter.

sum = 0;

for (int i = 0; i < N_samples; i++){
digitalWrite(tx_pin,HIGH);              //Step the voltage high on conductor 1.
delayMicroseconds(100);            //Delay to reach steady state.
digitalWrite(tx_pin,LOW);               //Step the voltage to zero on conductor 1.
sum += diff;                       //Sums up N_samples of these measurements.
}
return sum;
}                         //End of tx_rx function.

void loop() {

result = tx_rx();
result = map(result, 0, 4095, 0, 1024);  //As XIAO RP2040 has 12bit ADC, it takes 4095 values so I changed parameters
Serial.println(result);
delay(100);
}
``````

Troubles encountered

• At first the response from the controller was nothing. It turned out the connection was wrong. As I saw TX and RX in the program, thought need to use TX and RX both pins. But xiao rp2040's RX pin is digital pin, so I should have connected analog pin instead.
• I did not have appropriate pin headers for Adrian's board. So I tried to solder my jumper cable onto the board's outlet pattern. The soldering was challenging but I managed to complete it. But I heated too much that the pattern almost gone away.
• I just used the same program, without understand map function. As a result parameter of map function was not correct, because the controller was different. This case I use XIAO RP 2040 which has 12 bit ADC, so I can have 0-4095 values. Then I had to change the parameters of map function accordingly.
• Map function is used to re-map a number from one range to another. 2nd and 3rd parameter shows input range and 4th and 5th parameter shows converted range. This case 12 bit range changed into 10 bit range.

Thoughts and feelings

• It was amazing the simple sensor detect things. But I am not yet learned well what the figure means.
• If I touched one side, it shows positive figures, other shows negative figures. But if I touched both it shows higher positive figures than single positive response.
• If I touched my finger or metal thing, the response is obvious, but if I touched with plastic or wood, the response is not so clear. It probably means conductivity matters.
• I want to use this for my final project to detect something on the tray. But need to study more.
(end of document)