docs + first potmeter program

This commit is contained in:
2025-02-17 15:55:12 +01:00
parent b6a6f04333
commit 72bf01a813
37 changed files with 222 additions and 26 deletions

View File

@@ -153,10 +153,10 @@ In this case minVal is 800 an maxVal is 2200. So we need to stay between these r
At the local lecture we got thought how to use platformIO. I was already used to Arduino IDE v2. But I found the UI and the speeds of PlatformIO very nice so that's why I decided to switch to PlatformIO.
First off. I created a new project with the Xiao espC3 because the espC6 isn't registered on the list. I've googled a bit and that's because PlatformIO needs to get profit so they ask money to the board developers to add the board to their platform. So we need to set the correct board later on.
![alt text](image-3.png)
![alt text](image-3.jpg)
When it created the project. I copied all the files over to the src folder and renament my drone.ino to main.cpp. Now I had a lot of include errors because Arduino IDE automatically imports everything and with PlatformIO you need to define everything yourself. So I started out in the Library manager installing all the libraries to the project I needed.
![alt text](image-4.png)
![alt text](image-4.jpg)
#### Setting the correct board
@@ -184,7 +184,7 @@ To get the correct configuration if it isn't listed on PlatformIO, is to go to t
#### Installing libraries in platformIO
To install a library click the platformIO icon. In there click the libraries button. Then you can search a library and click add to project. Now you have added a library to your project!
![alt text](image.png)
![alt text](image.jpg)
After that it will edit platformio.ini and there you will see the library added to the project. It's also in `.pio/libdeps`
@@ -194,23 +194,23 @@ When setting up PlatformIO on another system we ran into the issue that the mach
### Programming and compiling and uploading
Using platformIO is really straight forward. The only folder you should look at in your platformIO project is the `src` folder.
![alt text](image-5.png)
![alt text](image-5.jpg)
In the main.cpp file you can write your program to run on a microcontroller.
On the bottom of your screen you see that there are a few new buttons.
![alt text](image-6.png)
![alt text](image-6.jpg)
The Compile and Upload and Serial console buttons are going to be the most used. Compile compiles the code and checks if it's correct. If it has incorrect syntax you need to correct it. The upload button compiles the code first and then sends it to the Microcontroller. The Serial console is a really nice debug tool to see what the microcontroller is doing if you added print statements in your code.
## Editing the new driver
Adding in support for the BNO085. The original driver doesn't support the BNO085.
I first started off searching for every instance of an existing sensor.
![alt text](image-7.png)
![alt text](image-7.jpg)
From there I started out changing everything to BNO085 and also importing the correct library. As I have found the correct library earlier in the code.
![alt text](image-8.png)
![alt text](image-8.jpg)
### The purple text (Compiler flags)
The purple text are compiler flags. They tell the compiler what to do with certain pieces of code or variables.
@@ -227,42 +227,110 @@ The purple text are compiler flags. They tell the compiler what to do with certa
### Setting the correct library
I added a compiler case for my sensor and added the correct library to it.
![alt text](image-8.png)
![alt text](image-8.jpg)
### Setting correct value selection
I am not sure what it does. It sets some values for the calculations later on. So I copied over the configuration for the MPU6050 because it was the most similar to the BNO085. ![alt text](image-9.png)
I am not sure what it does. It sets some values for the calculations later on. So I copied over the configuration for the MPU6050 because it was the most similar to the BNO085. ![alt text](image-9.jpg)
### Setting up the sensor
For this part I went into the documentation of the Sparkfun BNO0xx library. I first looked through the rest of the code what values it wanted because with the BNO085 you need to enable which information you want.
![alt text](image-11.png)
![alt text](image-11.jpg)
When digging deeper into the driver to where it pulls the data from the sensors you can see what values it want's and according to that I can go through the documentation to enable the correct data outputs.
I went to the [examples list](https://github.com/sparkfun/SparkFun_BNO080_Arduino_Library/tree/main/examples) of the library and clicked every data example I needed.
![alt text](image-12.png)
![alt text](image-12.jpg)
I first clicked the data type I needed.
![alt text](image-13.png)
![alt text](image-13.jpg)
Then I copied the line that enabled the data output.
![alt text](image-10.png)
![alt text](image-10.jpg)
Then I inserted it into the driver code.
### Getting data from the sensors
This step goes similar to the last step except you need to copy over another bit.
![alt text](image-14.png)
![alt text](image-14.jpg)
What this part does is acquire the sensor data and storing it in a variable. The same needs to be done in the driver like this.
![alt text](image-15.png)
![alt text](image-15.jpg)
The only issue is that the BNO085 can't output degrees. So we need to convert the radians to degrees using a simple formula I found on google.
![alt text](image-16.png)
![alt text](image-16.jpg)
The same also has to be done later on in the error correction algorithm
![alt text](image-17.png)
![alt text](image-17.jpg)
That was the last we needed to change. Hopefully it works now since I still need to fix some compile errors.
## Creating my own controls
I want to create my own controller. So I need to edit the current controls. The base driver attempts to set up radio communication. We won't be using that so I'm gonna comment that out.
![alt text](image-18.jpg)
When attempting to compile it still throws some errors so there are still functions being called from the original radio script. The error log indicated it comes from line 1239
![alt text](image-20.jpg)
![alt text](image-19.jpg)
So I will be needing to make my own case to control the drone.
I wanna control to drone using another microcontroller, specifically an esp because then I can use the espNOW protocol to connect them together and get communication running between them. First I wanna make something functional before I upgrade it so that's why I'm starting out easy.
### Components for the controller
Im going to start off with 2 sliding potentiometers and a espC3 for throttle and for left-right. The Driver expects PWM frequencies so I'm sending PWM frequencies based on the potsliders.
![alt text](IMG_8180.jpg)
* [PotSlider](https://nl.aliexpress.com/item/1005006733220962.html) x2
* [espC3 supermini](https://nl.aliexpress.com/item/1005008125438785.html) x1
### Wiring the controller
To read the Pot meter values we need to read the resistance from the potslider. So we need analog read. When looking at the datasheet I can see that I can use pins from 0 to 5.
![alt text](image-21.jpg)
Wiring it is pretty straight forward, VCC to 3v3, GND to GND and the out pin to a analog pin.
![alt text](IMG_8182.jpg)
### Programming the controller
#### Testing if I can upload
I started out by creating a new PlatformIO project. And selected the `Lolin Wemos C3 Mini`. Then I tried to upload some code to see if it worked.
![alt text](image-22.jpg)
In short the answer was yes. I was a bit surprised because the ESP-C3 supermini isn't in the list of platformIO.
#### Reading the Potentiometer
Reading the potentiometer is really straightforward. The only line we need is `analogRead()`, something to tell the pin that's it an input and something to print it to console.
```cpp
#include <Arduino.h>
void setup(){
Serial.begin(9600); //Opens serial bus
pinMode(0, INPUT); //sets pin 0 to input
}
void loop(){
Serial.println(analogRead(0)); //prints the result of analogRead() to console
}
```
When attempting to upload this I got this error a few times.
![alt text](image-23.jpg)
Then I remembered from the local lecture that if you `press and hold boot > press reset > release boot`. You can start the microcontroller in boot mode so you can easily flash to it.
After flashing it onto the microcontroller I could test it.
![alt text](image-24.jpg)
![alt text](image-25.jpg)
I've noticed there are some ghost values when it needs to be 0 so I need a small area where it's always 0. The upper side of the Potentiometer is always 4095 thats the max value so that's good.
##### Fixing the ghost measurements
Im going to map everything lower than 80 to 80 using software. The reason im doing 80 is because then it will keep on counting up from 80 instead of jumping from 0 to 81 and I didn't see any ghost readings above 80.