Raspberry Pi Build HAT
Raspberry Pi Build HAT
Raspberry Pi
Documentation
Computers
Accessories
Microcontrollers
Services
Pico C SDK
Build HAT
NOTE
NOTE
NOTE
NOTE
tall headers
The following pins are used by the Build HAT itself and
you should not connect anything to them.
GPIO0/1 ID prom
GPIO4 Reset
GPIO14 Tx
GPIO15 Rx
You will need to reboot at this point if you have made any
changes.
NOTE
NOTE
Connecting a Motor
connect motor
motor_a = Motor('A')
motor_a.run_for_seconds(5)
motor_a.run_for_seconds(5, speed=50)
motor_a.run_for_seconds(5, speed=-50)
motor_a = Motor('A')
while True:
print("Position: ", motor_a.get_aposition())
Run the program. Grab the motor and turn the shaft. You
should see the numbers printed in the Thonny REPL
changing.
NOTE
button = ForceSensor('C')
cs = ColorSensor('B')
def handle_pressed(force):
cs.on()
print(cs.get_color())
def handle_released(force):
cs.off()
button.when_pressed = handle_pressed
button.when_released = handle_released
pause()
WARNING
$ cd buildhat
Running C# Code
You can run the program with the dotnet run
command. Let’s try it now to make sure everything works.
It should print "Hello World!"
$ dotnet run
Hello World!
Editing C# Code
In the instructions below, you will be editing the Ple
buildhat/Program.cs, the C# program which was
generated when you ran the above commands.
brick.Dispose();
WARNING
NOTE
if (Brick.IsActiveSensor(sensor))
{
ActiveSensor activeSensor = brick.GetActiveSensor((SensorPort)i);
}
else
{
var passive = (Sensor)brick.GetSensor((SensorPort)i);
Console.WriteLine(passive.IsConnected);
}
Events
Console.WriteLine("Move motor on Port A to more than position 100 to stop this test.");
brick.WaitForSensorToConnect(SensorPort.PortA);
var active = (ActiveMotor)brick.GetMotor(SensorPort.PortA);
bool continueToRun = true;
active.PropertyChanged += MotorPropertyEvent;
while (continueToRun)
{
Thread.Sleep(50);
}
active.PropertyChanged -= MotorPropertyEvent;
Console.WriteLine($"Current position: {active.Position}, eventing stopped.");