# Input devices

## Group assignment && individual assignment
We first tested with the oscilloscopes and a potentiometer. We connected the potentiometer to A oscilloscope and a arduino to digital read it and analog read it.

The more we pushed the potentiometer the higher the voltage became. So the voltage drop was decreasing and that was visible on the oscilloscope.

![alt text](image-5.jpg)

![alt text](image-6.jpg)

![alt text](image-18.jpg)
Communication of oneWire Humidity sensor

Later on Henk connected a ds18b20 to a signal analyzer and tried reading the protocol. Afterwards we did it ourselves to see the communication between a mcu and a ultrasonic sensor.
![alt text](image-19.jpg)
Here you can see the trigger and the echo pin being pulled to high. 

Here is an example of the RX pin being used when sending data to the MCU. We hooked up the logic analyser to the Rx pin of the arduino to see if we can see the communication
![alt text](image-20.jpg)

## Potentiometer/Joysticks
For this week I want to get proper readings from my joysticks. I got them from aliexpress and couldn't find any datasheets on them. So I gotta test them out myself. With 3.3 volts I got good measurements when sliding the joystick to the lest and bad measurements when going to the right. When fully to the right it was hanging around 2400 and sometimes jittering to 2700. With a controller for a drone I don't want any jittering so I need to figure out how to make them completely stable. On my first board I had a lot of errors. When I was soldering the multiplexer the first time I accidentally rotated it 180 degrees. So I asked Henk for help de-soldering it. 
![alt text](IMG_9293.jpg)

![alt text](IMG_9319.jpg)
This was my setup of my first board. The multiplexer worked straight away luckily but getting good readings from the joystick was a a lot harder than I thought. Because I couldn't get to 0 and was getting jitters.

With my second board I implemented a 5v voltage regulator. But after testing it my mcu kept reporting 0 to 3 millivolts on the pin. Which was odd. When I placed my multimeter between the input pin and the ground it reported 2.5 volts.

![alt text](image-8.jpg)
![alt text](image-9.jpg)
When fully to the right it won't drop to 0 but when to the left it goes to 4095 on the edge so I thought it maybe was that it needed 5v instead of 3.3v.


So now I wanna test on a arduino to see if it works right on 5 volts. If it does I need to figure something out to either get 5v on the esp of another way of communicating between another mcu and esp. I can't use the VIN of the esp because I want to use batteries. When using batteries there isn't going to be 5v supplied on the VIN. Or maybe I should use a power bank. Then I do have 5v out.
![alt text](IMG_9347.JPEG)
Setup with joystick and arduino.
![alt text](image-10.jpg)
![alt text](image-11.jpg)

Using 5v with the arduino I get a lot more stable values. So now I need to try 5v with the esp and attempt to read it. If that works I am going to use the VIN for 5v supply.

When testing with the esp and bridging the wires I realised something. Maybe the multiplexer also needs 5v to forward anything below 5 volts. So I milled a new board with 5v supply to the multiplexer. With this design.

![alt text](image-12.jpg)

![alt text](image-13.jpg)

After debugging for a while Henk asked me what was wrong and then it all clicked. I went to re read the documentation on how voltage dividers worked [from this website](https://www.khanacademy.org/science/electrical-engineering/ee-circuit-analysis-topic/ee-resistor-circuits/a/ee-voltage-divider) and I then it all clicked. I first needed the lower Ohm to the input pin and then before the ground a higher resistor. So like this
![alt text](image-14.jpg) 
Instead of this.
![alt text](image-15.jpg)
This is still a bit complicated because I am using 2 resistors at the ground because I needed 20K Ohm but we only had 10K Ohm so I set 2 10K Ohm in series to create 20K Ohm.

During debugging I first removed the multiplexer and created a bypass to attempt to isolate the problem.
![alt text](IMG_9350.jpg)

Then I still struggled the entire day debugging and then I gave up and went home. In the morning Henk used the rubber ducky method and I found the problem and fixed it like this.
Before
![alt text](IMG_9351.jpg)
After
![alt text](IMG_9355.jpg)
It looks super messy but what I have done is. I broke one trace and created the same configuration as in the correct schematic. I connected the resistors wrongly and that caused all the power to go to ground instead of dividing the voltage to the analog pin and the ground.

Now that this works I can work on the final design of the board and send it to a board house.
![alt text](image-16.jpg)
This is my final design that I am going to send to the board house. I don't need any bridge resistors because I can do 2 layers with vias.


![alt text](image-17.jpg)
I needed to submit my board 2 additional times because the first board was still faulty. The second board I forgot to export the solder masks and with the third one It got confirmed and accepted!
Something else I found out is that if you order 5 boards you get a big discount on the shipping so that saved about 10 dollars.
## Voltage divider
This week I learned how voltage dividers worked and I also struggled a lot with them. A voltage divider is better for splitting voltage instead of creating a voltage drop using a single resistor. Because you don't have to know how much current is flowing. Instead you can divide the voltage between 2 lanes. This way you can receive an 5v analog signal on a esp without frying it.

![alt text](image321.jpg)
I found a lot of helpful explanation on [this website](https://www.khanacademy.org/science/electrical-engineering/ee-circuit-analysis-topic/ee-resistor-circuits/a/ee-voltage-divider).


## The drone control board
This week I've also started testing with the drone motors and electronic speed controllers. I have worked a bit with them in the past but not much. I have made this board so I could test the motors reliably because sending signals over breadboards can be super unreliable.

![alt text](IMG_9369.jpg)

I've also screwed it into a plate otherwise the IMU would give all sorts of random measurements and I needed exact measurements.

## Sources
* https://www.khanacademy.org/science/electrical-engineering/ee-circuit-analysis-topic/ee-resistor-circuits/a/ee-voltage-divider