You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using GPIO allows you to control pins for input or output high and low levels, which is commonly used to read signals or output control signals.
7
+
Using GPIOs allows you to control a pin to output a high or low voltage level or to read a signal from it. This is a very common way to read signals or output control signals.
6
8
7
-
**Note:** The pins on the `MaixCAM` are tolerant to `3.3V`. Do not input`5V`voltage.
9
+
**Note:** The pins on the `MaixCAM` are `3.3V` tolerant. **Do not** apply`5V`to them.
8
10
9
-
## Using GPIO in MaixPy
11
+
## Prerequisites
10
12
11
-
> MaixPy Firmware should > 4.1.2(not include)
13
+
Please learn how to use the [pinmap](https://www.google.com/search?q=./pinmap.md) module to set pin functions first.
12
14
13
-
First, we need to know which pins and GPIOs the device has. For MaixCAM, each pin corresponds to a GPIO controller, as shown in the figure:
15
+
To enable a pin for `GPIO` functionality, first use `pinmap` to set the function of the corresponding pin to `GPIO`.
It is important to note that pins can be used not only as GPIOs but also for other functions like PWM. Before using them, we need to set the pin function to GPIO.
19
+
First, you need to know which pins on your device are available as GPIOs, as shown in the figure:
19
20
20
-
For example, on MaixCAM, **some pins are already occupied by other functions by default, such as UART0 and WiFi (SDIO1 + A26), so it is not recommended to use them.**
| MaixCAM || The silkscreen on the board, e.g., `A19`, is the pin name, and `GPIOA19/PWM7` is the function name |
24
+
| MaixCAM-Pro || The first name, e.g., `A19`, is the pin name, and `GPIOA19/PWM7` is the corresponding function name |
25
+
| MaixCAM2 || The first name, e.g., `IO0_A2`, is the pin name, and `GPIO0_A2/SPI1_CS0` is the corresponding function name |
21
26
22
-
Other pins can be used, and the A14 pin is connected to the onboard LED, which is used as a system load indicator by default. If initialized, it will automatically disable the system indicator function and can be used as a regular GPIO (note that `A14` can only be used as an output). This way, you can control the LED's on and off state.
27
+
Note that pins may have other default uses. It's best to avoid these pins. Please refer to the [pinmap](https://www.google.com/search?q=./pinmap.md) documentation for details.
23
28
24
-
Here is the English translation of your text:
29
+
## Circuit Considerations
25
30
26
-
The circuit diagram of the LED is shown in the figure. Therefore, we only need to provide a high signal to pin A14, and the LED will conduct and light up:
27
-

31
+
Be aware that the voltage tolerance and load capacity of the pins are limited. You need to be careful when designing circuits to avoid basic mistakes, like asking "why can't the pin directly power a motor?"
32
+
33
+
***Pin Voltage Tolerance**: Unless otherwise specified, the pins operate at `3.3v`. Do not connect an external `5v` voltage.
34
+
***Pin Input/Output Current**: The input/output current of the chip pins is limited. They are generally only used for control signals. For devices with high current requirements, please use a conversion circuit.
35
+
36
+
**Example**: To control an LED, a simple circuit is as follows:
37
+
The `LED` is directly powered by a high-level output from the pin. This is the most intuitive way to use it, but you must be very careful. The maximum output and input current of a chip pin (the driving capability) is limited and is usually described in the chip's datasheet.
38
+
Here, the current is `3.3v/(LED+resistor resistance)`\<`0.64mA`, so it can be driven directly. However, if your circuit's current is too high, it may fail to drive the device or even cause the chip to malfunction.
39
+
40
+
The **correct approach** is to connect an external conversion circuit so the pin only acts as a control signal. This can be done using a transistor, optocoupler, or relay. This document won't go into details; please do your own research.
41
+
42
+
## GPIO Output Mode
43
+
44
+
As shown in the LED circuit diagram, we only need to provide a high voltage level to the `A14` (`MaixCAM2` is `IO0_A6`) pin for the LED to turn on:
Here, we first use `pinmap` to set the function of the `A14` pin to `GPIO`. Of course, for `A14`, since it only has the `GPIO` function, it can be omitted. For the sake of generality, other pins may need to be set, so it is set in this example.
61
+
* First, get the pin and function name based on the board model.
62
+
* Use `pinmap` to set the pin's function to `GPIO`.
63
+
*`err.check_raise` is used to check the return value of `set_pin_function`. If there's an error, it raises an exception to prevent mistakes.
64
+
* Initialize the `GPIO` object and set it to output mode.
65
+
* The output value is toggled every `0.5s`, causing the LED to blink.
42
66
43
-
For more APIs, please refer to the [GPIO API Documentation](https://wiki.sipeed.com/maixpy/api/maix/peripheral/gpio.html)
67
+
For more API information, please see the [GPIO API documentation](https://wiki.sipeed.com/maixpy/api/maix/peripheral/gpio.html).
Both MaixCAM and MaixCAM-Pro have a small LED light connected to pin `A14`. Additionally, the MaixCAM-Pro has an onboard illumination LED connected to pin `B3`, which is turned on by a high signal and off by a low signal:
84
+
Both `MaixCAM / MaixCAM-Pro` and `MaixCAM2` have a small LED connected to pins `A14` and `IO0_A6`.
85
+
Additionally, the `MaixCAM-Pro` and `MaixCAM2` also have an onboard **illumination LED** connected to pins `B3` and `IO0_A25`, respectively, which turns on with a high voltage and off with a low voltage:
To enable an pin for `I2C` functionality, first use `pinmap` to set the function of the corresponding pin to `I2C`.
11
15
12
-
For MaixCAM, due to limited pin resources, the pins for `I2C1` and `I2C3` overlap with those of the WiFi module (SDIO1). Therefore, you can only use either WiFi or hardware I2C, but not both. Additionally, there is an `I2C5`, which is simulated by software at the lower driver level. It is recommended to use this one, as the drivers are already set up, and its use is the same as using hardware `I2C`.
16
+
## I2C Introduction
13
17
14
-
By default, the pins for `I2C5` are configured as `GPIO`. Therefore, before using the `i2c` module, you should first use the `pinmap` module to set the pin functions to `I2C5` as follows:
18
+
`I2C` uses only two pins, `SCL` and `SDA`, to achieve bus communication. This allows one master to connect to multiple slaves, enabling convenient one-to-many communication.
19
+
It is commonly used for:
20
+
21
+
* Reading sensor data, such as temperature and humidity, IMU, and touchscreens.
22
+
* Controlling devices, such as setting camera parameters.
23
+
* Communication between two devices.
24
+
25
+
There are many good tutorials on the basics of I2C online. This article will not go into detail; please search and learn on your own.
26
+
27
+
## Choosing the Right I2C to Use
28
+
29
+
First, we need to know which pins and I2C interfaces the device has, as shown in the figure:
| MaixCAM || The silkscreen on the board, e.g., `A15`, is the pin name, and `I2C5_SCL` is the function name |
34
+
| MaixCAM-Pro || The first name, e.g., `A15`, is the pin name, and `I2C5_SCL` is the corresponding function name |
35
+
| MaixCAM2 || The first name, e.g., `IO0_A1`, is the pin name, and `I2C6_SCL` is the corresponding function name |
36
+
37
+
It's important to note that pins might have other default uses. It's best to avoid these pins. Please refer to the [pinmap](https://www.google.com/search?q=./pinmap.md) documentation for details.
38
+
39
+
For example:
40
+
* For `MaixCAM / MaixCAM-Pro`, the `I2C1` and `I2C3` pins overlap with the WiFi module (SDIO1), so their use is not recommended. There is also an `I2C5`, which is a software-simulated driver at the low level. It is recommended to use it as the underlying driver has been configured, and it works the same as a hardware `I2C`.
41
+
* The `I2C6 / I2C7` pins on `MaixCAM2` are idle and can be used once `pinmap` is configured.
42
+
43
+
## Using I2C in MaixPy
44
+
45
+
First, use `pinmap` to set the pin function to `I2C`, then initialize the `I2C` object:
For more APIs, see [i2c API documentation](https://wiki.sipeed.com/maixpy/api/maix/peripheral/i2c.html).
78
+
## More Examples
79
+
80
+
See [MaixPy examples](https://github.com/sipeed/MaixPy/tree/main/examples/peripheral/i2c).
81
+
82
+
## API Documentation
83
+
84
+
For more API information, see [i2c API documentation](https://wiki.sipeed.com/maixpy/api/maix/peripheral/i2c.html).
85
+
86
+
## Using Other Libraries
87
+
88
+
Additionally, since it is a standard Linux driver, besides using the APIs provided by MaixPy, you can also use general Linux libraries like `smbus / smbus2`.
89
+
90
+
Steps to use:
91
+
92
+
* Run `pip install smbus` in the development board's terminal to install the library.
93
+
* Use `pinmap` to map the pin functions.
94
+
* Call `smbus` APIs to read from and write to `i2c`.
29
95
30
-
As mentioned above, for the `MaixCAM`, you must choose between using hardware `I2C` and `WiFi`. If you need to use `I2C`, you must disable `WiFi` and use the `pinmap` module to set the pin functions for `I2C`, then operate using the `maix.i2c` module.
31
-
> TODO: Provide a method to disable WiFi (requires disabling the WiFi driver in the system, which is more complex).
0 commit comments