io_pin
Pin #
Bases: IntEnum
The pins available for configuration and reading via the io pin service.
Pins 17 and 18 are not available
Source code in src/kaspersmicrobit/services/io_pin.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
PinAD #
Bases: Enum
The analog-digital configuration of a pin
Source code in src/kaspersmicrobit/services/io_pin.py
40 41 42 43 44 45 |
|
PinIO #
Bases: Enum
The input-output configuration of a pin
Source code in src/kaspersmicrobit/services/io_pin.py
48 49 50 51 52 53 |
|
PinIOConfiguration #
Bases: PinConfiguration[PinIO]
The IO pin configuration. Contains for each pin whether it is used for INPUT or OUTPUT
Source code in src/kaspersmicrobit/services/io_pin.py
94 95 96 97 98 99 100 101 102 103 |
|
PinADConfiguration #
Bases: PinConfiguration[PinAD]
The AD pin configuration. Contains for each pin whether it is for ANALOG or DIGITAL use
Source code in src/kaspersmicrobit/services/io_pin.py
106 107 108 109 110 111 112 113 114 115 |
|
PinValue
dataclass
#
The pin and its value
Attributes:
-
pin
(Pin
) –the pin
-
value
(int
) –the value of the pin (given how this value is sent over Bluetooth) the value loses precision (the least significant 2 bits are not sent) This means, for example, that a value 1-3 is sent as 0 and 255 as 252.
Source code in src/kaspersmicrobit/services/io_pin.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
PwmControlData
dataclass
#
A class to give PWM commands to the micro:bit
Attributes:
-
pin
(Pin
) –the pin for which the command is intended
-
value
(int
) –a value in the range (0-1024) (0 means disabled)
-
period
(int
) –the period in microseconds
Source code in src/kaspersmicrobit/services/io_pin.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
IOPinService #
This class contains the functions that you can access in connection with the io pins on the edge of the micro:bit
These are all options offered by the Bluetooth IO PIN service
See Also: https://tech.microbit.org/hardware/edgeconnector/
See Also: https://www.micro-bit.nl/kennisbank-pinnen
See Also: https://lancaster-university.github.io/microbit-docs/ble/iopin-service/
Source code in src/kaspersmicrobit/services/io_pin.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
is_available #
is_available() -> bool
Checks whether the I/O pin Bluetooth service is found on the connected micro:bit.
Returns:
-
bool
–true if the I/O pin service was found, false if not.
Source code in src/kaspersmicrobit/services/io_pin.py
205 206 207 208 209 210 211 212 |
|
notify_data #
notify_data(callback: Callable[[List[PinValue]], None])
You can call this method when you want to be notified of the value of pins. You need these pins previously configured as PinIO.INPUT pins via write_io_configuration. You will be notified when the value changes.
Parameters:
-
callback
(Callable[[List[PinValue]], None]
) –a function called with a list of PinValue objects
Raises:
-
BluetoothServiceNotFound
–When the I/O pin service is not active on the micro:bit
-
BluetoothCharacteristicNotFound
–When the I/O pin service is active but there was no way to activate the notifications for the PIN data (normally does not occur)
Source code in src/kaspersmicrobit/services/io_pin.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
read_data #
read_data() -> List[PinValue]
Returns the values for each pin configured as PinIO.INPUT via write_io_configuration.
Returns:
-
List[PinValue]
–A list of input pins and their associated values
Raises:
-
BluetoothServiceNotFound
–When the I/O pin service is not active on the micro:bit
-
BluetoothCharacteristicNotFound
–When the I/O pin service is active but there was no way to read the pin data (normally does not occur)
Source code in src/kaspersmicrobit/services/io_pin.py
231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
write_data #
write_data(values: List[PinValue])
Writes values to 1 or more pins. You must have previously configured these pins as PinIO.OUTPUT pins via write_io_configuration. When you write to an input pin it will be ignored
Parameters:
-
values
(List[PinValue]
) –the output pins and their associated values
Raises:
-
BluetoothServiceNotFound
–When the I/O pin service is not active on the micro:bit
-
BluetoothCharacteristicNotFound
–When the I/O pin service is active but there was no way to write the pin data (normally does not occur)
Source code in src/kaspersmicrobit/services/io_pin.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
read_ad_configuration #
read_ad_configuration() -> PinADConfiguration
Returns for each pin whether it is configured as a PinAD.DIGITAL or PinAD.ANALOG pin.
Returns:
-
PinADConfiguration
–The analog-digital configuration for each pin
Raises:
-
BluetoothServiceNotFound
–When the I/O pin service is not active on the micro:bit
-
BluetoothCharacteristicNotFound
–When the I/O pin service is active but there was no way to read the pin analog-digital configuration (normally does not occur)
Source code in src/kaspersmicrobit/services/io_pin.py
262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
write_ad_configuration #
write_ad_configuration(config: PinADConfiguration)
Configure each pin for analog or digital use.
Parameters:
-
config
(PinADConfiguration
) –The analog-digital configuration for each pin
Raises:
-
BluetoothServiceNotFound
–When the I/O pin service is not active on the micro:bit
-
BluetoothCharacteristicNotFound
–When the I/O pin service is active but there was no way to write the analog-digital configuration (normally not present)
Source code in src/kaspersmicrobit/services/io_pin.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
read_io_configuration #
read_io_configuration() -> PinIOConfiguration
Returns for each pin whether it is configured as a PinIO.INPUT or PinIO.OUTPUT pin.
Returns:
-
PinIOConfiguration
–The input-output configuration for each pin
Raises:
-
BluetoothServiceNotFound
–When the I/O pin service is not active on the micro:bit
-
BluetoothCharacteristicNotFound
–When the I/O pin service is active but there was no way to read the input-output configuration (normally does not occur)
Source code in src/kaspersmicrobit/services/io_pin.py
291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
write_io_configuration #
write_io_configuration(config: PinIOConfiguration)
Configure each pin for input or output. Only values of pins configured as PinIO.INPUT can be read with read_data, and for these pins only you can get updates with notify_data. You can write values only to pins configured as PinIO.OUTPUT.
Parameters:
-
config
(PinIOConfiguration
) –The input-output configuration for each pin
Raises:
-
BluetoothServiceNotFound
–When the I/O pin service is not active on the micro:bit
-
BluetoothCharacteristicNotFound
–When the I/O pin service is active but there was no way to write the input-output configuration (normally not present)
Source code in src/kaspersmicrobit/services/io_pin.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
write_pwm_control_data #
write_pwm_control_data(
pwm_control1: PwmControlData,
pwm_control2: PwmControlData = None,
)
Writes Pulse Width Modulation commands to the micro:bit. 1 or 2 assignments can be given at the same time
See Also: https://microbit-micropython.readthedocs.io/en/latest/pin.html
See Also: https://www.micro-bit.nl/kennisbank-pinnen
Parameters:
-
pwm_control1
(PwmControlData
) –a PWM command
-
pwm_control2
(PwmControlData
, default:None
) –an optional PWM command
Raises:
-
BluetoothServiceNotFound
–When the I/O pin service is not active on the micro:bit
-
BluetoothCharacteristicNotFound
–When the I/O pin service is active but there was no way to write the pwm control data (normally does not occur)
Source code in src/kaspersmicrobit/services/io_pin.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|