mirror of
https://gitlab.waag.org/make/fablab/interns/2025/sam.git
synced 2025-08-03 11:54:58 +00:00
docs update
This commit is contained in:
@@ -500,4 +500,56 @@ So the main MCU would do all the thinking and readings from the sensors and the
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
So now I could send commands to the motors over Serial and see the motors spin in realtime. The command is structured like this. `1,500` Where 1 is the motor number and 500 is the speed of the motor. So like this I could control every motor separately.
|
So now I could send commands to the motors over Serial and see the motors spin in realtime. The command is structured like this. `1,500` Where 1 is the motor number and 500 is the speed of the motor. So like this I could control every motor separately.
|
||||||
|
|
||||||
|
## Getting ultrasonic sensors to work (Again)
|
||||||
|
On the last day I tried to connect everything together. I first started out with one ultrasonic sensor but I noticed I wasn't getting any data from it. So I started debugging and only running the code necessary to get the sensor running but that also didn't work
|
||||||
|
|
||||||
|
??? Code
|
||||||
|
```cpp
|
||||||
|
int trigPin = D4; // Trigger
|
||||||
|
int echoPin = D9; // Echo
|
||||||
|
long duration, cm, inches;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
//Serial Port begin
|
||||||
|
Serial.begin(9600);
|
||||||
|
//Define inputs and outputs
|
||||||
|
pinMode(trigPin, OUTPUT);
|
||||||
|
pinMode(echoPin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
|
||||||
|
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
|
||||||
|
digitalWrite(trigPin, LOW);
|
||||||
|
delayMicroseconds(5);
|
||||||
|
digitalWrite(trigPin, HIGH);
|
||||||
|
delayMicroseconds(10);
|
||||||
|
digitalWrite(trigPin, LOW);
|
||||||
|
|
||||||
|
// Read the signal from the sensor: a HIGH pulse whose
|
||||||
|
// duration is the time (in microseconds) from the sending
|
||||||
|
// of the ping to the reception of its echo off of an object.
|
||||||
|
duration = pulseIn(echoPin, HIGH);
|
||||||
|
|
||||||
|
// Convert the time into a distance
|
||||||
|
cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343
|
||||||
|
inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135
|
||||||
|
|
||||||
|
Serial.print(inches);
|
||||||
|
Serial.print("in, ");
|
||||||
|
Serial.print(cm);
|
||||||
|
Serial.print("cm");
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
delay(250);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
I double, triple checked every connection and grabbed new wires in case that was the issue. After a while a directly connected it to the mcu but that also didn't work and then I gave up.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
After going to Henk and reading the datasheet he said I needed to use 5 volts instead of 3.3 volts
|
||||||
|
When I changed that connection it worked.
|
Reference in New Issue
Block a user