diff --git a/content/hardware/09.mega/boards/category.md b/content/hardware/09.mega/boards/category.md new file mode 100644 index 0000000000..f468aa41cb --- /dev/null +++ b/content/hardware/09.mega/boards/category.md @@ -0,0 +1,3 @@ +--- +title: Boards +--- \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/compatibility.yml b/content/hardware/09.mega/boards/giga-r1-wifi/compatibility.yml new file mode 100644 index 0000000000..3ce900e0f0 --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/compatibility.yml @@ -0,0 +1,10 @@ +software: + - arduino-ide + - arduino-cli + - web-editor +hardware: + boards: ~ + carriers: ~ + shields: + - 4-relays-shield + - motor-shield-rev3 \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/GIGA_R1_WiFi_Block_Diagram.png b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/GIGA_R1_WiFi_Block_Diagram.png new file mode 100644 index 0000000000..c28e57cb01 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/GIGA_R1_WiFi_Block_Diagram.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/GIGA_R1_WiFi_Power_Tree.png b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/GIGA_R1_WiFi_Power_Tree.png new file mode 100644 index 0000000000..c7b13a1bf5 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/GIGA_R1_WiFi_Power_Tree.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/featured.png b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/featured.png new file mode 100644 index 0000000000..7232340962 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/featured.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaMechanical.png b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaMechanical.png new file mode 100644 index 0000000000..6f3d32b585 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaMechanical.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaR1WiFiBottom.png b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaR1WiFiBottom.png new file mode 100644 index 0000000000..9083bac080 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaR1WiFiBottom.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaR1WiFiTop.png b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaR1WiFiTop.png new file mode 100644 index 0000000000..43e60e57fa Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/assets/gigaR1WiFiTop.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/datasheet.md b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/datasheet.md new file mode 100644 index 0000000000..72e069de5f --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/datasheet/datasheet.md @@ -0,0 +1,433 @@ +--- +identifier: ABX00063 +title: Arduino® GIGA R1 WiFi +type: maker +author: Ali Jahangiri +--- + +![](assets/featured.png) + +# Description + +The Arduino GIGA R1 WiFi brings the power of the STM32H7 to the Mega form factor, being the first Mega board to include onboard Wi-Fi® and Bluetooth® connectivity. The board provides 76 digital inputs/outputs (12 with PWM capability), 14 analog inputs and 2 analog outputs (DAC) all easily accessible via pin headers. The STM32 microprocessor with dual-core Cortex® M7 and Cortex® M4, together with onboard memory and audio jack enables you to perform machine learning and signal processing on the edge. + +# Target Areas + +3D printing, Signal Processing, Maker, Robotics + +# Features + +- **STM32H747XIH6** Microcontroller + - Dual-core + - 32-bit Arm® Cortex®-M7 core with double-precision FPU and L1 cache up to 480 MHz + - 32-bit Arm® 32-bit Cortex®-M4 core with FPU up to 240 MHz + - Full set of DSP instructions + - Memory Protection Unit (MPU) +- **Murata® 1DX** Wi-Fi®/Bluetooth® Module + - Wi-Fi® 802.11b/g/n 65 Mbps + - Bluetooth® Low Energy (version 5.X via Cordio stack, version 4.2 via Arduino Stack) + - Micro UFL connector for external antenna +- **Memory** + - **STM32H747XI** + - 2 MB Flash + - 1 MB RAM + - **AT25SF128A-MHB-T** + - 16 MB NOR Flash + - QSPI Interface + - **AS4C4M16SA** + - 8 MB SDRAM +- **I/O** + - Digital I/O Pins: 76 + - Analog input pins: 12 + - PWM pins: 12 + - Analog output pins (DAC0/DAC1): 2 + - USB Host: USB 2.0 A + - USB Peripheral: USB-C® + - Logic level: 3.3V + - VRTC: To power the RTC while the board is off + - OFF pin: To turn off the board +- **Communication** + - 4x UART + - 3x I2C + - 2x SPI + - 1x CAN (an external transceiver is required) +- **Secure Element** ATECC608A-MAHDA-T Module +- **USB** + - **USB Host** USB 2.0 Type A + - Host + - **USB Peripheral** USB-C® + - Programming Port + - HID +- **Connectors** + - Camera: 20 pin Arducam camera connector + - Display: D1N, D0N, D1P, D0P, CKN, CKP, D68-D75 + - Audio jack: DAC0, DAC1, A7 + - JTAG connector +- **Power** + - Circuit operating voltage: 3.3V + - Input voltage (VIN): 6-24V + - DC Current per I/O Pin: 8 mA + + +# Contents + +# The Board + +## Application Examples + +The GIGA R1 WiFi combines the best of the Portenta H7 and the Mega 2560. A generous amount of I/O easily accessible via pins allows for easy and fast testing of new ideas and solutions. The STM32H7 has ample power to handle machine-learning tasks. Your IoT projects can even benefit from the Arduino IoT Cloud with the help of the onboard secure element and its wireless connectivity. + +- **3D Printing:** The Mega form factor has been very popular for creating 3D printers. Connect sensors to the high-resolution ADC interfaces for high-performance sensing of the 3D printing process. Together with the dual-core computing power, control the printing process like never before. Monitor filament usage and print status locally over Bluetooth® or from anywhere in the world with the Arduino IoT Cloud, or any other third-party service, and its Wi-Fi® features. + +- **Audio Processing:** The GIGA R1 WiFi provides a 3.5 mm audio input/output to easily interact with audio signals in the environment. Analyse and create audio signals directly on the board. Connect a microphone and control a wide range of digital and analog devices. Create your own musical instrument and change the note through the various inputs. Create an online concert with the Arduino IoT Cloud or any other third-party service and connect with people all over the world. + +- **Data acquisition device:** Thanks to the numerous analog inputs, including the jack connector (J15) and the two DAC outputs with a resolution up to 12 bits, you can create your own data acquisition device. Make your own multimeter or even an oscilloscope and create an online dashboard with the Arduino IoT Cloud or any other third-party service. Design your own electrochemical experiments, apply custom current/voltage waveforms and check the status of your experiment from the comfort of your home. + +## Accessories + +- Micro UFL antenna (Included) +- USB-C® cable (Not included) +- USB 2.0 Type-A cable (Not included) + +## Related Products + +- Arduino Mega Proto Shield Rev3 (A000080) +- Arduino 4 Relays Shield (A000110) +- Arduino Motor Shield Rev3 (A000079) + +# Rating + +## Recommended Operating Conditions + +| Symbol | Description | Min | Typ | Max | Unit | +|-----------------|----------------------------------|--------------------|-----|--------------------|------| +| VIN | Input voltage from VIN pad | 6 | 7.0 | 32 | V | +| VUSB | Input voltage from USB connector | 4.8 | 5.0 | 5.5 | V | +| VDD | Input high-level voltage | 0.7*VDD | | VDD | V | +| VIL | Input low-level voltage | 0 | | 0.3*VDD | V | +| TOP | Operating Temperature | -40 | 25 | 85 | °C | + +**Note:** VDD controls the logic level and is connected to the 3.3V power rail. VAREF is for the analog logic. + +
+ +# Functional Overview + +## Block Diagram + +![Arduino GIGA R1 WiFi Block Diagram](assets/GIGA_R1_WiFi_Block_Diagram.png) + +## Board Topology + +### Front View + +![Top View of Arduino GIGA R1 WiFi](assets/gigaR1WiFiTop.png) + +| **Ref.** | **Description** | **Ref.** | **Description** | +|----------|-----------------------------------------|----------|-------------------------------------| +| U1 | STM32H7 Dual Core Microcontroller IC | U8 | AT25SF128A-MHB-T 16 MB Flash IC | +| U3 | AS4C4M16SA 8MB SDRAM IC | U4 | ATECC608A-MAHDA-T Secure Element IC | +| U5 | LBEE5KL1DX-883 Wi-Fi®/Bluetooth® Module | U6 | MP2322GQH Buck Converter 3.3V IC | +| U7 | MP2269GD-Z Buck Converter 5V IC | JANALOG | Analog input/output headers | +| JDIGITAL | Digital input/output headers | JSIDE | Digital input/output headers | +| SPI | SPI headers | JTAG | JTAG Headers | +| J2 | USB 2.0 A Host | J15 | 3.5 mm audio in/out | +| PB1 | RESET Button | PB2 | BOOT0 button | +| J14 | Micro UFL connector | J5 | Camera | +| J6 | Camera | DL1 | Power LED | +| DL2 | RGB SMLP34RGB2W3 Common anode LED | J12 | CX90B-16P USB-C® connector | + +### Back View + +![Back View of Arduino GIGA R1 WiFi](assets/gigaR1WiFiBottom.png) + +## Processor + +The GIGA R1 WiFi's main processor is the dual-core STM32H747 (U1) including a Cortex® M7 running at 480 MHz and a Cortex® M4 running at 240 MHz. The two cores communicate via a _Remote Procedure Call_ mechanism that allows calling functions between each processor seamlessly. + +## Wi-Fi®/Bluetooth® Connectivity + +The Murata® LBEE5KL1DX-883 wireless module (U5) simultaneously provides Wi-Fi® and Bluetooth® connectivity in an ultra-small package based on the Cypress CYW4343W. The IEEE802.11 b/g/n Wi-Fi® interface can be operated as an access point (AP), station (STA) or as a dual mode simultaneous AP/STA and supports a maximum transfer rate of 65 Mbps. Bluetooth® interface supports Bluetooth® Classic and Bluetooth® Low Energy. An integrated antenna circuitry switch allows a single external antenna (J14) to be shared between Wi-Fi® and Bluetooth®. + +## Onboard Memories + +The GIGA R1 WiFi supplements the 2 MB Flash and 1 MB SRAM on the STM32H747 (U1) with 16 MB of NOR Flash with the AT25SF128A-MHB-T (U8) as well as 8 MB of SDRAM with the AS4C4M16SA (U3). U8 connects over a Quad-SPI interface to the main processor (U1). U3 operates at a frequency of 166 MHz. + +## USB Connector + +Two USB ports are provided on the Arduino GIGA R1 WiFi. One USB 2.0 type A (J2) and a USB-C® (J12). The USB 2.0 connector allows external devices to be connected as peripherals, while the USB-C® connector allows the GIGA board to be connected as a peripheral for other devices. Note that super speed pins on the USB-C® connector (J12) are unpopulated. A TVS diode array is placed on the VBUS of each connector (D4, D2) for ESD protection purposes. + +## Audio + +The STM32H7 (U1) has two digital-to-analog converters (DAC) which drive the stereo audio output on the 3.5 mm jack connector (J15). Each DAC has a resolution of up to 12 bits. The right and left channels are also accessible via pins DAC0 and DAC1 respectively. A microphone input is also present on the jack connector (J15), which is shared with analog pin A7. The _Buffered mode_ in the STM32H7 can allow for low-impedance output while _Sample and hold_ functionality can help to reduce power consumption. Up to 10 mega samples per second are supported. + +
+ +## Power Tree + +![Arduino GIGA R1 WiFi Power Tree](assets/GIGA_R1_WiFi_Power_Tree.png) + +Power can either be supplied via the VIN pins, or the 5V of the USB connectors (J2, J12). If power is supplied via VIN, the MP2269GD-Z (U7) buck converter steps the voltage down to 5V. The 5V power rail is then stepped down to 3.3V by the MP2322GQH (U6) buck converter. The logic level of components on the Arduino GIGA R1 WiFi is 3.3V. + +## Board Operation + +### Getting Started - IDE + +If you want to program your GIGA R1 WiFi while offline you need to install the Arduino® Desktop IDE **[1]**. To connect the GIGA R1 WiFi to your computer, you will need a Type-C® USB cable, which can also provide power to the board, as indicated by the LED (DL1). + +### Getting Started - Arduino Web Editor + +All Arduino boards, including this one, work out-of-the-box on the Arduino® Web Editor **[2]**, by just installing a simple plugin. + +The Arduino Web Editor is hosted online, therefore it will always be up-to-date with the latest features and support for all boards. Follow **[3]** to start coding on the browser and upload your sketches onto your board. + +### Getting Started - Arduino IoT Cloud + +All Arduino IoT enabled products are supported on Arduino IoT Cloud which allows you to log, graph and analyze sensor data, trigger events, and automate your home or business. + +### Online Resources + +Now that you have gone through the basics of what you can do with the board you can explore the endless possibilities it provides by checking exciting projects on ProjectHub **[4]**, the Arduino Library Reference **[5]**, and the online store **[6]**; where you will be able to complement your board with sensors, actuators and more. + +### Board Recovery + +All Arduino boards have a built-in bootloader which allows flashing the board via USB. In case a sketch locks up the processor and the board is not reachable anymore via USB, it is possible to enter bootloader mode by double-tapping the reset button right after the power-up. + +# Mechanical Information + + +## Pinout + +### Three-Pins Header - J1 +| Pin | Function | Type | Description | +|-----|----------|---------|-------------------------| +| 1 | OFF | Digital | 3V3 Enable Pin (U6) | +| 2 | GND | Power | Ground | +| 3 | VRTC | Reset | Real Time Clock Battery | + + +### Analog + +| Pin | Function | Type | Description | +| ---- | ---------- | --------- | ----------------------------------------------- | +| 1 | NC | NC | Not Connected | +| 2 | IOREF | IOREF | Reference for digital logic V - connected to 3.3V | +| 3 | Reset | Reset | Reset | +| 4 | +3V3 | Power | +3V3 Power Rail | +| 5 | +5V | Power | +5V Power Rail | +| 6 | GND | Power | Ground | +| 7 | GND | Power | Ground | +| 8 | VIN | Power | Voltage Input | +| 9 | A0 | Analog | Analog input 0 /GPIO | +| 10 | A1 | Analog | Analog input 1 /GPIO | +| 11 | A2 | Analog | Analog input 2 /GPIO | +| 12 | A3 | Analog | Analog input 3 /GPIO | +| 13 | A4 | Analog | Analog input 4 /GPIO | +| 14 | A5 | Analog | Analog input 5 /GPIO | +| 15 | A6 | Analog | Analog input 6 /GPIO | +| 16 | A7 | Analog | Analog input 7 /GPIO | +| 17 | A8 | Analog | Analog input 8 /GPIO | +| 18 | A9 | Analog | Analog input 9 /GPIO | +| 19 | A10 | Analog | Analog input 10 /GPIO | +| 20 | A11 | Analog | Analog input 11 /GPIO | +| 21 | DAC0 | Analog | Digital to Analog Converter 0 | +| 22 | DAC1 | Analog | Digital to Analog Converter 1 | +| 23 | CANRX | Digital | CAN Bus Receive | +| 24 | CANTX | Digital | CAN Bus Transfer | + +### Digital + +| Pin | Function | Type | Description | +|-----|----------|---------|------------------------------------------| +| 1 | D21/SCL1 | Digital | GPIO 21/I2C 1 Clock | +| 2 | D20/SDA1 | Digital | GPIO 20/I2C 1 Dataline | +| 3 | AREF | Digital | Analog Reference Voltage | +| 4 | GND | Power | Ground | +| 5 | D13/SCK | Digital | GPIO 13/SPI Clock | +| 6 | D12/CIPO | Digital | GPIO 12/SPI Controller In Peripheral Out | +| 7 | D11/COPI | Digital | GPIO 11/SPI Controller Out Peripheral In | +| 8 | D10/CS | Digital | GPIO 10/SPI Chip Select | +| 9 | D9/SDA2 | Digital | GPIO 9/I2C 2 Dataline | +| 10 | D8/SCL2 | Digital | GPIO 8/I2C 2 Clockline | +| 11 | D7 | Digital | GPIO 7 | +| 12 | D6 | Digital | GPIO 6 | +| 13 | D5 | Digital | GPIO 5 | +| 14 | D4 | Digital | GPIO 4 | +| 15 | D3 | Digital | GPIO 3 | +| 16 | D2 | Digital | GPIO 2 | +| 17 | D1/TX0 | Digital | GPIO 1 / Serial 0 Transmitter | +| 18 | D0/TX0 | Digital | GPIO 0 / Serial 0 Receiver | +| 19 | D14/TX3 | Digital | GPIO 14 / Serial 3 Transmitter | +| 20 | D15/RX3 | Digital | GPIO 15 / Serial 3 Receiver | +| 21 | D16/TX2 | Digital | GPIO 16 / Serial 2 Transmitter | +| 22 | D17/RX2 | Digital | GPIO 17 / Serial 2 Receiver | +| 23 | D18/TX1 | Digital | GPIO 18 / Serial 1 Transmitter | +| 24 | D19/RX1 | Digital | GPIO 19 / Serial 1 Receiver | +| 25 | D20/SDA | Digital | GPIO 20 / I2C 0 Dataline | +| 26 | D21/SCL | Digital | GPIO 21 / I2C 0 Clock | + +### STM32 ICSP + +| Pin | Function | Type | Description | +|-----|----------|----------|------------------------------| +| 1 | CIPO | Internal | Controller In Peripheral Out | +| 2 | +5V | Internal | Power Supply of 5V | +| 3 | SCK | Internal | Serial Clock | +| 4 | COPI | Internal | Controller Out Peripheral In | +| 5 | RESET | Internal | Reset | +| 6 | GND | Internal | Ground | + +### Digital Pins D22 - D53 LHS + +| Pin | Function | Type | Description | +|-----|----------|---------|----------------| +| 1 | +5V | Power | +5V Power Rail | +| 2 | D22 | Digital | GPIO 22 | +| 3 | D24 | Digital | GPIO 24 | +| 4 | D26 | Digital | GPIO 26 | +| 5 | D28 | Digital | GPIO 28 | +| 6 | D30 | Digital | GPIO 30 | +| 7 | D32 | Digital | GPIO 32 | +| 8 | D34 | Digital | GPIO 34 | +| 9 | D36 | Digital | GPIO 36 | +| 10 | D38 | Digital | GPIO 38 | +| 11 | D40 | Digital | GPIO 40 | +| 12 | D42 | Digital | GPIO 42 | +| 13 | D44 | Digital | GPIO 44 | +| 14 | D46 | Digital | GPIO 46 | +| 15 | D48 | Digital | GPIO 48 | +| 16 | D50 | Digital | GPIO 50 | +| 17 | D52 | Digital | GPIO 52 | +| 18 | GND | Power | Ground | + +### Digital Pins D22 - D53 RHS + +| Pin | Function | Type | Description | +|-----|----------|---------|----------------| +| 1 | +5V | Power | +5V Power Rail | +| 2 | D23 | Digital | GPIO 23 | +| 3 | D25 | Digital | GPIO 25 | +| 4 | D27 | Digital | GPIO 27 | +| 5 | D29 | Digital | GPIO 29 | +| 6 | D31 | Digital | GPIO 31 | +| 7 | D33 | Digital | GPIO 33 | +| 8 | D35 | Digital | GPIO 35 | +| 9 | D37 | Digital | GPIO 37 | +| 10 | D39 | Digital | GPIO 39 | +| 11 | D41 | Digital | GPIO 41 | +| 12 | D43 | Digital | GPIO 43 | +| 13 | D45 | Digital | GPIO 45 | +| 14 | D47 | Digital | GPIO 47 | +| 15 | D49 | Digital | GPIO 49 | +| 16 | D51 | Digital | GPIO 51 | +| 17 | D53 | Digital | GPIO 53 | +| 18 | GND | Power | Ground | + +## Mounting Holes And Board Outline + +![Mechanical View of Arduino GIGA R1 WiFi](assets/gigaMechanical.png) + +
+ +# Certifications + +## Declaration of Conformity CE DoC (EU) + +We declare under our sole responsibility that the products above are in conformity with the essential requirements of the following EU Directives and therefore qualify for free movement within markets comprising the European Union (EU) and European Economic Area (EEA). + +## Declaration of Conformity to EU RoHS & REACH 211 01/19/2021 + +Arduino boards are in compliance with RoHS 2 Directive 2011/65/EU of the European Parliament and RoHS 3 Directive 2015/863/EU of the Council of 4 June 2015 on the restriction of the use of certain hazardous substances in electrical and electronic equipment. + +| **Substance** | **Maximum Limit (ppm)** | +|----------------------------------------|-------------------------| +| Lead (Pb) | 1000 | +| Cadmium (Cd) | 100 | +| Mercury (Hg) | 1000 | +| Hexavalent Chromium (Cr6+) | 1000 | +| Poly Brominated Biphenyls (PBB) | 1000 | +| Poly Brominated Diphenyl ethers (PBDE) | 1000 | +| Bis(2-Ethylhexyl} phthalate (DEHP) | 1000 | +| Benzyl butyl phthalate (BBP) | 1000 | +| Dibutyl phthalate (DBP) | 1000 | +| Diisobutyl phthalate (DIBP) | 1000 | + +Exemptions : No exemptions are claimed. + +Arduino Boards are fully compliant with the related requirements of European Union Regulation (EC) 1907 /2006 concerning the Registration, Evaluation, Authorization and Restriction of Chemicals (REACH). We declare none of the SVHCs (), the Candidate List of Substances of Very High Concern for authorization currently released by ECHA, is present in all products (and also package) in quantities totaling in a concentration equal or above 0.1%. To the best of our knowledge, we also declare that our products do not contain any of the substances listed on the "Authorization List" (Annex XIV of the REACH regulations) and Substances of Very High Concern (SVHC) in any significant amounts as specified by the Annex XVII of Candidate list published by ECHA (European Chemical Agency) 1907 /2006/EC. + +## Conflict Minerals Declaration + +As a global supplier of electronic and electrical components, Arduino is aware of our obligations with regards to laws and regulations regarding Conflict Minerals, specifically the Dodd-Frank Wall Street Reform and Consumer Protection Act, Section 1502. Arduino does not directly source or process conflict minerals such as Tin, Tantalum, Tungsten, or Gold. Conflict minerals are contained in our products in the form of solder, or as a component in metal alloys. As part of our reasonable due diligence Arduino has contacted component suppliers within our supply chain to verify their continued compliance with the regulations. Based on the information received thus far we declare that our products contain Conflict Minerals sourced from conflict-free areas. + +## FCC Caution + +Any Changes or modifications not expressly approved by the party responsible for compliance could void the user’s authority to operate the equipment. + +This device complies with part 15 of the FCC Rules. Operation is subject to the following two conditions: + +(1) This device may not cause harmful interference + +(2) this device must accept any interference received, including interference that may cause undesired operation. + +**FCC RF Radiation Exposure Statement:** + +1. This Transmitter must not be co-located or operating in conjunction with any other antenna or transmitter. + +2. This equipment complies with RF radiation exposure limits set forth for an uncontrolled environment. + +3. This equipment should be installed and operated with a minimum distance of 20 cm between the radiator & your body. + +English: +User manuals for licence-exempt radio apparatus shall contain the following or equivalent notice in a conspicuous location in the user manual or alternatively on the device or both. This device complies with Industry Canada licence-exempt RSS standard(s). Operation is subject to the following two conditions: + +(1) this device may not cause interference + +(2) this device must accept any interference, including interference that may cause undesired operation of the device. + +French: +Le présent appareil est conforme aux CNR d’Industrie Canada applicables aux appareils radio exempts de licence. L’exploitation est autorisée aux deux conditions suivantes : + +(1) l’ appareil nedoit pas produire de brouillage + +(2) l’utilisateur de l’appareil doit accepter tout brouillage radioélectrique subi, même si le brouillage est susceptible d’en compromettre le fonctionnement. + +**IC SAR Warning:** + +English +This equipment should be installed and operated with a minimum distance of 20 cm between the radiator and your body. + +French: +Lors de l’ installation et de l’ exploitation de ce dispositif, la distance entre le radiateur et le corps est d ’au moins 20 cm. + +**Important:** The operating temperature of the EUT can’t exceed 85℃ and shouldn’t be lower than -40℃. + +Hereby, Arduino S.r.l. declares that this product is in compliance with essential requirements and other relevant provisions of Directive 201453/EU. This product is allowed to be used in all EU member states. + +| Frequency bands | Maximum output power (ERP) | +|----------------------|----------------------------| +| 2.4 GHz, 40 channels | TBD | + +## Company Information + +| Company name | Arduino SRL | +|-----------------|-----------------------------------------------| +| Company Address | Via Andrea Appiani, 25 - 20900 MONZA(Italy) | + + +## Reference Documentation + +| Ref | Link | +|---------------------------|-------------------------------------------------------------------------------------------------| +| Arduino IDE (Desktop) | | +| Arduino IDE (Cloud) | | +| Cloud IDE Getting Started | | +| Project Hub | | +| Library Reference | | +| Online Store | | + +## Change Log + +| **Date** | **Changes** | +|------------|-------------| +| 03/02/2023 | Release | diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-cad-files.zip b/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-cad-files.zip new file mode 100644 index 0000000000..1c95d3e7a4 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-cad-files.zip differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-full-pinout.pdf b/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-full-pinout.pdf new file mode 100644 index 0000000000..754da3e1aa Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-full-pinout.pdf differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-pinout.png b/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-pinout.png new file mode 100644 index 0000000000..24c2e8c9a5 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-pinout.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-schematics.pdf b/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-schematics.pdf new file mode 100644 index 0000000000..01a18108fb Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/downloads/ABX00063-schematics.pdf differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/essentials.md b/content/hardware/09.mega/boards/giga-r1-wifi/essentials.md new file mode 100644 index 0000000000..3de1e5f4dc --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/essentials.md @@ -0,0 +1,30 @@ + + + A quick guide to installing your board with the Arduino IDE. + + + + + + + + A list of libraries that come bundled with the Mbed core. + + + + Advanced ADC and DAC features. + + + + + + + Built-in Examples are sketches included in the Arduino IDE and demonstrate all basic Arduino commands. + + + Discover interesting articles, principles and techniques related to the Arduino ecosystem. + + + Arduino programming language can be divided in three main parts: functions, values (variables and constants), and structure. + + \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/features.md b/content/hardware/09.mega/boards/giga-r1-wifi/features.md new file mode 100644 index 0000000000..d570865c8d --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/features.md @@ -0,0 +1,51 @@ + + +The GIGA R1 WiFi comes with a USB-C connector for programming, communication and HID functionality, a USB-A connector for connecting devices such as USB sticks and keyboards. It features a 3.5 mm audio jack for connecting speakers, microphones etc. Dedicated camera & display connectors are located at the top of the board, which can also be connected from underneath. + +With a fast dual core microcontroller (480MHz / 240MHz), 76 GPIOs, several communication buses, you can build large projects using the GIGA R1 WiFi as a base. The GIGA R1 WiFi also comes equipped with a radio module, crypto chip and an antenna. + + + + + + +A reference to all technical features on this board, with pointers to additional documents. + + + + +Learn more about the ADC/DAC features of the GIGA R1 WiFi board, and discover examples for Audio projects. + + + + +The STM32H747XI has two cores that can be programmed separately (M4/M7). You can for example run MicroPython and Arduino code simultaneously and communicate via an RPC. + + + + + +The GIGA R1 WiFi comes with a Murata LBEE5KL1DX-883 radio module for Wi-Fi/Bluetooth® communication. + + + + + +The GIGA R1 WiFi has support for MicroPython, which can be set up in just minutes. + + + + + +This board has USB-C for power/programming/communication line, and a USB-A for connecting USB devices (keyboards, mass storage). + + + + + +Learn how to connect a camera via the dedicated connector. + + + + + diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/image.svg b/content/hardware/09.mega/boards/giga-r1-wifi/image.svg new file mode 100644 index 0000000000..9796f0b66f --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/image.svg @@ -0,0 +1,1160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/interactive/ABX00063-pinout.png b/content/hardware/09.mega/boards/giga-r1-wifi/interactive/ABX00063-pinout.png new file mode 100644 index 0000000000..24c2e8c9a5 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/interactive/ABX00063-pinout.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/interactive/altium.zip b/content/hardware/09.mega/boards/giga-r1-wifi/interactive/altium.zip new file mode 100644 index 0000000000..1c95d3e7a4 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/interactive/altium.zip differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/product.md b/content/hardware/09.mega/boards/giga-r1-wifi/product.md new file mode 100644 index 0000000000..8b5f7a128a --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/product.md @@ -0,0 +1,8 @@ +--- +title: GIGA R1 WiFi +url_shop: https://store.arduino.cc/giga-r1-wifi +url_guide: /tutorials/giga-r1/giga-getting-started +core: arduino:mbed_giga +--- + +The **GIGA R1 WiFi** is a powerful, feature-packed board with a large amount of GPIOs and dedicated connectors. Based on the [STM32H747XI](/resources/datasheets/stm32h747xi.pdf) micro based on the [Mbed OS](https://os.mbed.com/), the GIGA R1 WiFi features 76 GPIOs, a [dual core processor](/tutorials/giga-r1-wifi/giga-dual-core), [advanced ADC/DAC](/tutorials/giga-r1-wifi/giga-audio) features as well as camera & display connectors. It also has a rich [USB interface](/tutorials/giga-r1-wifi/giga-usb) with support for HID via USB-C and USBHost (keyboard, mass storage) via a dedicated USB-A connector. diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tech-specs.md b/content/hardware/09.mega/boards/giga-r1-wifi/tech-specs.md new file mode 100644 index 0000000000..d389413c69 --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tech-specs.md @@ -0,0 +1 @@ +Here you will find the technical specifications for the Arduino® GIGA R1 WiFi. \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tech-specs.yml b/content/hardware/09.mega/boards/giga-r1-wifi/tech-specs.yml new file mode 100644 index 0000000000..e1290e8bd8 --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tech-specs.yml @@ -0,0 +1,34 @@ +Board: + Name: Arduino® GIGA R1 WiFi + SKU: ABX00063 +Microcontroller: STM32H747XI dual Cortex®-M7+M4 32bit low power Arm® MCU +USB: + USB-C: Programming Port / HID + USB-A: Host (enable with PA_15) +Pins: + Digital I/O Pins: 76 + Analog input pins: 12 + DAC: 2 (DAC0/DAC1) + PWM pins: 12 + Misc: VRTC & OFF pin +Communication: + UART: Yes, 4x + I2C: Yes, 3x + SPI: Yes, 2x + CAN: Yes (requires an external transceiver). +Connectors: + Camera: I2C + D54-D67 + Display: D1N, D0N, D1P, D0P, CKN, CKP + D68-D75 + Audio Jack: DAC0, DAC1, A7 +Power: + Circuit operating voltage: 3.3V + Input voltage (VIN): 6-24V + DC Current per I/O Pin: 8 mA +Clock speed: + Main core: 480 MHz + Second core: 240 MHz +Memory: + STM32H747XI: 2MB Flash, 1MB RAM +Dimensions: + Width: 25 mm + Length: 66 mm \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/BOOT0.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/BOOT0.png new file mode 100644 index 0000000000..e1ccf2740e Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/BOOT0.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/STM32H747XI.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/STM32H747XI.png new file mode 100644 index 0000000000..056621fff5 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/STM32H747XI.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/audio-jack.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/audio-jack.png new file mode 100644 index 0000000000..9e240981e0 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/audio-jack.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/canpins.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/canpins.png new file mode 100644 index 0000000000..052d0a346a Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/canpins.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/i2cpins.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/i2cpins.png new file mode 100644 index 0000000000..ffd313da87 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/i2cpins.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/jtag.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/jtag.png new file mode 100644 index 0000000000..a3b61faf87 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/jtag.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/red_led_blink.gif b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/red_led_blink.gif new file mode 100644 index 0000000000..edef0fa7c0 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/red_led_blink.gif differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/rtc.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/rtc.png new file mode 100644 index 0000000000..eb6ce7ac44 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/rtc.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/schematics-spi.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/schematics-spi.png new file mode 100644 index 0000000000..bbc39cb29e Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/schematics-spi.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/spipins.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/spipins.png new file mode 100644 index 0000000000..cc2c26a286 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/spipins.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/usb.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/usb.png new file mode 100644 index 0000000000..530afccc08 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/usb.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/wifi.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/wifi.png new file mode 100644 index 0000000000..e8ed15167d Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/assets/wifi.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/cheat-sheet.md b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/cheat-sheet.md new file mode 100644 index 0000000000..bc15af5133 --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/cheat-sheet.md @@ -0,0 +1,981 @@ +--- +title: 'Arduino GIGA R1 Cheat Sheet' +description: 'Learn how to set up the GIGA R1, get a quick overview of the components, information regarding pins and how to use different Serial (SPI, I2C, UART), and much, much more.' +tags: + - Installation + - I2C + - SPI + - UART + - JTAG + - CAN + - DAC + - MIPI + - USBHost + - Arducam + - Audio Jack +author: 'Jacob Hylén' +hardware: + - hardware/08.mega/boards/giga-r1-wifi +software: + - ide-v1 + - ide-v2 + - web-editor +--- + +The **Arduino GIGA R1** is one of our most feature-packed Arduino boards to date, supported by the same powerful, ML-capable, dual-core microcontroller found in the Pro family's Portenta H7. It features support for display connectors, USB-host, an Audio Jack, an Arducam connector, a CAN bus, 4 UART Serial Ports, 2 I2C buses, dedicated DAC Pins, and much, much more. + +This article is a collection of resources and guides to make use of every great feature of this powerful hardware. + +You can also visit the documentation platform for the [GIGA R1](/hardware/giga-r1-wifi). + +## Datasheet + +The full datasheets are available as a downloadable PDF from the link below: + +- [Download the GIGA R1 datasheet](/resources/datasheets/ABX00063-datasheet.pdf) + +## Power Supply + +To power the **GIGA R1** you may either use a USB-C cable, or the VIN pin. + +If you're using the USB-C connector you must power it with 5V. + +Powering the board with the VIN pin gives you more options, as you can safely power the board with any voltage between 6-24V. + +By connecting the OFF pin to GND you can cut the power supply to the board, turning it off completely. Read more about this feature in the [OFF-pin](#off-pin) section of this article + +It should however be noted that the internal operating voltage of the microcontroller is 3.3V, and you should not apply voltages higher than that to the GPIO pins. + +## Installation + +***For detailed instructions on how to install the GIGA R1 core, please refer to the [Getting Started with GIGA R1](/tutorials/giga-r1-wifi/giga-getting-started) guide.*** + +The **GIGA R1** can be programmed through: + +- The **Classic Arduino IDE 1.8.X**, +- the **Arduino IDE 2.0.X**, +- and the Web-editor. + +## Core + +The GIGA R1 is based on the [Arduino Core for mbed devices](https://github.com/arduino/ArduinoCore-mbed), which also provides a set of examples that works out of the box. + +These examples are available in the Arduino IDE via **File > Examples > Examples for GIGA**. + +### Mbed OS + +As [Arduino Core for mbed devices](https://github.com/arduino/ArduinoCore-mbed) is based on [MbedOS](https://os.mbed.com/), it is possible for the operating system to crash while running a sketch. + +On most Arduino boards, when a sketch fails due to e.g. memory shortage, the board resets. + +On the GIGA R1, whenever the MbedOS fails, the board does **not reset automatically**. Instead, if it fails, the onboard red LED will start to blink in a looping pattern of 4 fast blinks and 4 slow blinks. + +***Please note, the red LED does NOT mean your board is broken or bricked.*** + +![Red LED blinking due to MbedOS crashing.](assets/red_led_blink.gif) + +In case you encounter the red LED, you can either: +- Press the reset button **once** (this resets the sketch). +- **Double-tap** the reset button to enter bootloader mode (allowing you to re-program the board). + +## Boot0 + +Pressing and holding the button labelled `BOOT0` on the board while powering the board will boot it into DFU-mode (Device Firmware Update), letting you reflash the bootloader without the use of external hardware, if you were to ever need to. + +![BOOT0 button](assets/BOOT0.png) + +The state of this button can also be read from a sketch while it is running, giving you a basic interactive component without needing to do any wiring. + +To read the state of the Boot0 button in your sketch, you use this line of code: + +```arduino +digitalRead(PC_13); +``` + +## STM32H747XI Microcontroller + +The GIGA R1 features the powerful dual core **STM32H747XI** microcontroller found on the Arduino PRO familys Portenta H7 board, but in a form factor accessible to any maker who has tinkered with an Arduino board before. + +The **STM32H747XI** is a powerful dual core chip, capable of being programmed with a high-level language such as MicroPython on one core, while simultaneously running Arduino compiled code on the other, and having the two programs communicate with each other seamlessly. + +![Microcontroller on the GIGA R1](assets/STM32H747XI.png) + +The microcontroller operates on a voltage of 3.3V, applying a higher voltage than that, such as 5V, to a pin might damage the microcontroller. + +## Memory + +### RAM + +The **GIGA R1** has 1 MB of SRAM that is internal to the processor, and 8MB of SDRAM which you can access and write to. + +To access the SDRAM you need to use the SDRAM library, include it in your sketch with: + +```arduino +#include "SDRAM.h" +``` + +Before writing to the SDRAM, you need to allocate it, the following code will create an array that reserves 7MB of the SDRAM for you to write to. +```arduino + uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024); +``` +If you now store any data in this array, it will be written to SDRAM. +```arduino +for (int i = 0; i<128; i++) { + myVeryBigArray[i] = i; + } +``` + +When you no longer need to use the SDRAM, you can free it, so it can be used for other things. + +```arduino +SDRAM.free(myVeryBigArray); +``` + + +### Flash + +The **GIGA R1** has 2MB of internal, and 16MB of external Flash storage. +The external Flash storage on the **GIGA R1** is QSPI and can be accessed and used to store data. If you need to, you can configure the board to act as a USB flash drive, so you can store files such as images, audio, and more. + +The GIGA firmware has full support for FATFS and littleFS. + +To access the QSPI flash storage as a USB flash drive, you need to follow a few steps, first you need to update the WiFi modules firmware, then you need to create partitions on the flash storage, before finally exposing the partitions to be detected by a computer. These three steps are broken down into different built in example sketches that conveniently all come with the GIGA core. + +Firstly, navigate in the IDE menu to `File > Examples > STM32H747_System > WiFiFirmwareUpdater` and upload the sketch to your board. + +In the Serial monitor you will now be able to interface with the board. Follow the instructions by sending a "**y**" in the monitor. You will now see the progress of the firmware update, don't power off the board until you see a message telling you that it is safe. + +After completing this, the next step is to partition the flash storage. Navigate to `File > Examples > STM32H747_System > QSPIFormat` and upload the sketch. From here, your interaction with the board will be very similar to when you updated the WiFi firmware. In the serial monitor, you will get the option to choose from two partition schemes. For this purpose, partition scheme 1 is good. Again, send "**y**" in the serial monitor and wait for confirmation before powering the board off. + +Lastly, navigate to `File > Examples > USB Mass Storage > AccessFlashAsUSBDisk` and upload the sketch. + +Once this is completed, you should now see a new storage device connected as a portable storage device in your computer. + +This can be very useful, as this flash storage **does not get deleted when you upload a new sketch to the board.** Meaning that you can store files on the board, and then upload a new sketch that can access and use those files without the need for an SD card and card reader. + +***Note: In this configuration, the USB serial port used for serial communication with the computer is occupied, so you won't be able to send or read information in the serial monitor. **This includes uploading new sketches. To upload a new sketch you need to put the GIGA R1 in DFU mode by double pressing the RST button.*** + +## Wi-Fi® / Bluetooth® LE + +![Murata LBEE5KL1DX-883 radio module + antenna connector.](assets/wifi.png) + +The Wi-Fi / Bluetooth® module onboard the GIGA R1 WiFi is the Murata LBEE5KL1DX-883. This module does not come with a built-in antenna, but an external antenna is included when purchasing the board. + +The antenna connector (see image above) is located right next to the USB-C connector, and is of a **U.FL.** type. + +To use the BLE features on this board, refer to the [ArduinoBLE library documentation](https://reference.arduino.cc/reference/en/libraries/arduinoble/). + +## Audio Jack + +The **GIGA R1** features an audio jack, with 2x DAC channels, and 1x ADC channel, and is capable of reading input from a microphone, as well as outputting sound through a speaker. + +![Audio jack.](assets/audio-jack.png) + +The audio jack is connected to the following pins: +- **A12 / DAC0** +- **A13 / DAC1** +- **A7** + +Both of these come with caveats, though. As there is no amplifier circuit on the board itself, driving a high impedance speaker directly without an amplifier circuit could cause damage to the board, and microphone input without an amplifier circuit between the microphone and the board may sound dim. + +In the coming sections we will provide resources and basic information on how to use the audio jack as both an input and an output. + + +### DAC Output + +In order to output audio from the DAC, you can use the `AdvancedAnalogRedux` library from Arduino. You will need to connect a speaker to your board either through the audio jack or the DAC pins. + +Include the library and create the `AdvancedDAC` object, such as the `dac1(A12)`, with the following code in the beginning of your sketch, outside of the `void setup()` function: + +```arduino +#include "AdvancedDAC.h" + +AdvancedDAC dac1(A12); +``` + +To initialize the library, and check that everything went as expected with the following piece of code: + +```arduino + if (!dac1.begin(AN_RESOLUTION_12, 8000, 32, 64)) { + Serial.println("Failed to start DAC!"); + while (1); + } +``` + +Then lastly, add the following code to `void loop()` to start: +```arduino +if (dac1.available()) { + + // Get a free buffer for writing + SampleBuffer buf = dac1.dequeue(); + + // Write data to buffer + for (int i=0; i + +constexpr unsigned long printInterval { 1000 }; +unsigned long printNow {}; + +void setup() { + Serial.begin(9600); + RTCset(); +} + +void loop() { + if (millis() > printNow) { + Serial.print("System Clock: "); + Serial.println(getLocaltime()); + printNow = millis() + printInterval; + } +} + +void RTCset() // Set cpu RTC +{ + tm t; + t.tm_sec = (0); // 0-59 + t.tm_min = (52); // 0-59 + t.tm_hour = (14); // 0-23 + t.tm_mday = (18); // 1-31 + t.tm_mon = (11); // 0-11 "0" = Jan, -1 + t.tm_year = ((22)+100); // year since 1900, current year + 100 + 1900 = correct year + set_time(mktime(&t)); // set RTC clock +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} +``` + +To get accurate time, you'll want to change the values in `void RTCset()` to whatever time it is when you're starting this clock. As long as the VRTC pin is connected to power, the clock will keep ticking and time will be kept accurately. + +### RTC Wi-Fi® Example + +With the following sketch, you can automatically set the time by requesting the time from a Network Time Protocol (NTP), using the UDP protocol. + +```arduino +/* + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + modified 28 Dec 2022 + by Giampaolo Mancini + +This code is in the public domain. + */ + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = ""; // your network SSID (name) +char pass[] = ""; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen for UDP packets + +// IPAddress timeServer(162, 159, 200, 123); // pool.ntp.org NTP server + +constexpr auto timeServer { "pool.ntp.org" }; + +const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +constexpr unsigned long printInterval { 1000 }; +unsigned long printNow {}; + +void setup() +{ + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + Serial.println("Connected to WiFi"); + printWifiStatus(); + + setNtpTime(); + +} + +void loop() +{ + if (millis() > printNow) { + Serial.print("System Clock: "); + Serial.println(getLocaltime()); + printNow = millis() + printInterval; + } +} + +void setNtpTime() +{ + Udp.begin(localPort); + sendNTPpacket(timeServer); + delay(1000); + parseNtpPacket(); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(const char * address) +{ + memset(packetBuffer, 0, NTP_PACKET_SIZE); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + Udp.beginPacket(address, 123); // NTP requests are to port 123 + Udp.write(packetBuffer, NTP_PACKET_SIZE); + Udp.endPacket(); +} + +unsigned long parseNtpPacket() +{ + if (!Udp.parsePacket()) + return 0; + + Udp.read(packetBuffer, NTP_PACKET_SIZE); + const unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + const unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + const unsigned long secsSince1900 = highWord << 16 | lowWord; + constexpr unsigned long seventyYears = 2208988800UL; + const unsigned long epoch = secsSince1900 - seventyYears; + set_time(epoch); + +#if defined(VERBOSE) + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // print Unix time: + Serial.println(epoch); + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second +#endif + + return epoch; +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +void printWifiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} + +``` + + +### VRTC Pin + +The GIGA R1 also features a `VRTC` pin, giving you the ability to power the RTC with a coin cell battery to keep the time even when your board is turned off, for low power timekeeping. + +![VRTC pin on the GIGA R1](./assets/rtc.png) + +## Camera Interface + +The Arduino GIGA features an onboard Arducam compatible connector. + +To learn more about the camera capabilities of the GIGA R1, check out the [GIGA R1 Camera Guide](/tutorials/giga-r1-wifi/giga-camera) + +## JTAG + +The **GIGA R1** features a 2x5 pin JTAG (Joint Test Action Group) connector, giving advanced debug functionalities for more advanced users. + +![JTAG Connector](assets/jtag.png) + +## CAN Bus + +The **GIGA R1** features a dedicated CAN bus. + +![CAN Bus](assets/canpins.png) + +***The CAN bus does not include a built in transceiver. If you need to use the CAN bus, you can add a transceiver as a breakout board.*** + +CAN, or **Controller Area Network**, is a communication standard that allows microcontroller-based devices to communicate with each other without the need for a host computer. This means that building a complex system with many different subsystems within becomes much easier. + +This makes the **GIGA R1** a powerful option for complex multilayered systems, as it can be integrated into existing systems or be used to build a new one from scratch. + +The CAN pins on the **GIGA R1** are labelled `CANRX` and `CANTX`. Typically, transceiver breakouts are labelled with a similar syntax, and to connect them to the board, use the following wiring scheme: + +| GIGA R1 | Transceiver | +| ------- | ----------- | +| VCC | 3.3V | +| GND | GND | +| CANTX | CANTX\* | +| CANRX | CANRX\* | + +***\*The name of CANTX/CANRX differs from product to product.*** + +Below is an example of how to send & receive data using a CAN bus. + +```arduino +#include "CAN.h" + +mbed::CAN can1(PB_5, PB_13); +uint8_t counter = 0; + +void send() { + Serial.println("send()"); + if (can1.write(mbed::CANMessage(1337, &counter, 1))) { + Serial.println("wloop()"); + counter++; + Serial.print("Message sent: "); + Serial.println(counter); + } else { + Serial.println("Transmission error"); + Serial.println(can1.tderror()); + can1.reset(); + } +} + +void receive() { + mbed::CANMessage msg; + if (can1.read(msg)) { + Serial.print("Message received: "); + Serial.println(msg.data[0]); + } +} + + +void setup() { + Serial.begin(115200); + can1.frequency(1000000); +} + +bool receiver = false; +void loop() { + if (receiver) { + receive(); + } else { + send(); + } + delay(1000); +} +``` + +## SPI + +![SPI Pins](assets/spipins.png) + +The **GIGA R1** features two separate SPI (Serial Peripheral Interface) buses, one is configured on the 6 pin header (ICSP) labelled SPI, and the other is broken out into pin connections on the board. + +The first bus (connector), `SPI` uses the following pins: + +- (CIPO) - D89 +- (COPI) - D90 +- (SCK) - D91 +- (CS) - D10 + +The second bus (header), `SPI1`, uses the following pins: + +- (CIPO) - D12 +- (COPI) - D11 +- (SCK) - D13 +- (CS) - unassigned, use any free GPIO for this. + +For using both SPI buses simultaneously, check out the following example: + +```arduino +#include + +const int CS_1 = 10; +const int CS_2 = 5; + +void setup() { + pinMode(CS_1, OUTPUT); + pinMode(CS_2, OUTPUT); + + SPI.begin(); + SPI1.begin(); + + digitalWrite(CS_1, LOW); + digitalWrite(CS_2, LOW); + + SPI.transfer(0x00); + SPI1.transfer(0x00); + + digitalWrite(CS_1, HIGH); + digitalWrite(CS_2, HIGH); +} + +void loop() { +} +``` + +Please note that the in the GIGA R1 schematics and the code does not match exactly. In the schematics, you will notice that `SPI` is `SPI1` and `SPI1` is `SPI5`. + +![SPI ports in the schematics.](assets/schematics-spi.png) + + +## I2C Pins + +I2C lets you connect multiple I2C compatible devices in series using only two pins. The controller will send out information through the I2C bus to a 7 bit address, meaning that the technical limit of I2C devices on a single line is 128. Practically, you're never gonna reach 128 devices before other limitations kick in. + +The **GIGA R1** has three separate I2C buses of which two are usable without external components, letting you control more devices. + +The pins used for I2C on the **GIGA R1** are the following: +- SDA - D20 +- SCL - D21 +- SDA1 - also available on the camera connector. +- SCL1 - also available on the camera connector. +- SDA2 - D9 +- SCL2 - D8 + +![I2C Pins](assets/i2cpins.png) + +To connect I2C devices you will need to include the [Wire](https://www.arduino.cc/reference/en/language/functions/communication/wire/) library at the top of your sketch. + +```arduino +#include +``` + +Inside `void setup()` you need to initialize the library, and initialize the I2C port you want to use. + +```arduino +Wire.begin() //SDA & SDL +Wire1.begin(); //SDA1 & SDL1 +Wire2.begin(); //SDA2 & SDL2 +``` + +And to write something to a device connected via I2C, we can use the following commands: + +```arduino +Wire.beginTransmission(1); //begin transmit to device 1 +Wire.write(byte(0x00)); //send instruction byte +Wire.write(val); //send a value +Wire.endTransmission(); //stop transmit +``` + +If you pay close attention you may notice that there are three sets of I2C pins. The two first sets (SDA, SCL, SDA1, SCL1) have internal pullup resistors connected to them which are required to make them function as I2C pins. + +If you want to use the third set (SDA2, SCL2) as I2C pins you will need to use external pullup resistors. + +## Serial/UART Pins + +The **GIGA R1** supports, like every other Arduino board, serial communication with UART (Universal Asynchronous, Receiver-Transmitter). However, the **GIGA R1** board features 4 separate serial ports. + +This not only means that you may print different values to different ports and monitor them separately, which is useful enough in and of itself, but that you may also communicate with **4 different serial enabled devices** simultaneously. + +The pins used for UART on the **GIGA R1** are the following: + +- RX0 - D0 +- TX0 - D1 +- RX1 - D19 +- TX1 - D18 +- RX2 - 17 +- TX2 - 16 +- RX3 - 15 +- TX3 - 14 + +Each Serial port works in the same way as the one you're used to, but you use different functions to target them: + +```arduino +Serial.begin(9600); +Serial1.begin(9600); +Serial2.begin(9600); +Serial3.begin(9600); +``` + +To send and receive data through UART, we will first need to set the baud rate inside `void setup()`. + +```arduino +Serial1.begin(9600); +``` + +To read incoming data, we can use a while loop() to read each individual character and add it to a string. + +```arduino + while(Serial1.available()){ + delay(2); + char c = Serial1.read(); + incoming += c; + } +``` + +And to write something, we can use the following command: + +```arduino +Serial1.write("Hello world!"); +``` + +## Pins + +The **GIGA R1** gives you access to more pins than any other Arduino board that is this accessible for makers. Many of them have special features that will be accounted for in the upcoming sections of this article. Keep reading to learn what you can do with them. + +If you just need a quick overview of the pins functionality, this is a full table of all the IO pins on the **GIGA R1** + +| Pin | Function | Notes | +| --- | --------- | -------------------- | +| 0 | TX | Serial communication | +| 1 | RX | Serial communication | +| 2 | PWM | PWM, Digital IO pin | +| 3 | PWM | PWM, Digital IO pin | +| 4 | PWM | PWM, Digital IO pin | +| 5 | PWM | PWM, Digital IO pin | +| 6 | PWM | PWM, Digital IO pin | +| 7 | PWM | PWM, Digital IO pin | +| 8 | PWM/SCL2 | PWM, Digital IO, I2C | +| 9 | PWM/SDA2 | PWM, Digital IO, I2C | +| 10 | PWM/CS | PWM, Digital IO, SPI | +| 11 | PWM/COPI | PWM, Digital IO, SPI | +| 12 | PWM/CIPO | PWM, Digital IO, SPI | +| 13 | PWM/SCK | PWM, Digital IO, SPI | +| 14 | TX3 | Serial communication | +| 15 | RX3 | Serial communication | +| 16 | TX2 | Serial communication | +| 17 | RX2 | Serial communication | +| 18 | TX1 | Serial communication | +| 19 | RX1 | Serial communication | +| 20 | SDA | Digital IO, I2C | +| 21 | SCL | Digital IO, I2C | +| 22 | GPIO | Digital IO pin | +| 23 | GPIO | Digital IO pin | +| 24 | GPIO | Digital IO pin | +| 25 | GPIO | Digital IO pin | +| 26 | GPIO | Digital IO pin | +| 27 | GPIO | Digital IO pin | +| 28 | GPIO | Digital IO pin | +| 29 | GPIO | Digital IO pin | +| 30 | GPIO | Digital IO pin | +| 31 | GPIO | Digital IO pin | +| 32 | GPIO | Digital IO pin | +| 33 | GPIO | Digital IO pin | +| 34 | GPIO | Digital IO pin | +| 35 | GPIO | Digital IO pin | +| 36 | GPIO | Digital IO pin | +| 37 | GPIO | Digital IO pin | +| 38 | GPIO | Digital IO pin | +| 39 | GPIO | Digital IO pin | +| 40 | GPIO | Digital IO pin | +| 41 | GPIO | Digital IO pin | +| 42 | GPIO | Digital IO pin | +| 43 | GPIO | Digital IO pin | +| 44 | GPIO | Digital IO pin | +| 45 | GPIO | Digital IO pin | +| 46 | GPIO | Digital IO pin | +| 47 | GPIO | Digital IO pin | +| 48 | GPIO | Digital IO pin | +| 49 | GPIO | Digital IO pin | +| 50 | GPIO | Digital IO pin | +| 51 | GPIO | Digital IO pin | +| 52 | GPIO | Digital IO pin | +| 53 | GPIO | Digital IO pin | +| 54 | GPIO | Digital IO pin | +| 55 | GPIO | Digital IO pin | +| 56 | GPIO | Digital IO pin | +| 57 | GPIO | Digital IO pin | +| 58 | GPIO | Digital IO pin | +| 59 | GPIO | Digital IO pin | +| 60 | GPIO | Digital IO pin | +| 61 | GPIO | Digital IO pin | +| 62 | GPIO | Digital IO pin | +| 63 | GPIO | Digital IO pin | +| 64 | GPIO | Digital IO pin | +| 65 | GPIO | Digital IO pin | +| 66 | GPIO | Digital IO pin | +| 67 | GPIO | Digital IO pin | +| 68 | GPIO | Digital IO pin | +| 69 | GPIO | Digital IO pin | +| 70 | GPIO | Digital IO pin | +| 71 | GPIO | Digital IO pin | +| 72 | GPIO | Digital IO pin | +| 73 | GPIO | Digital IO pin | +| 74 | GPIO | Digital IO pin | +| 75 | GPIO | Digital IO pin | +| A0 | Analog in | Analog In | +| A1 | Analog in | Analog In | +| A2 | Analog in | Analog In | +| A3 | Analog in | Analog In | +| A4 | Analog in | Analog In | +| A5 | Analog in | Analog In | +| A6 | Analog in | Analog In | +| A7 | Analog in | Analog In | +| A8 | Analog in | Analog In | +| A9 | Analog in | Analog In | +| A10 | Analog in | Analog In | +| A11 | Analog in | Analog In | +| A12 | DAC0 | Analog In, DAC | +| A13 | DAC1 | Analog In, DAC | +| A14 | CANRX | Analog In, CAN | +| A15 | CANTX | Analog In, CAN | + + + +### Analog Pins + +The **GIGA R1** has 12 analog input pins that can be read with a resolution of 16 Bits, by using the `analogRead()` function. + +```arduino +value = analogRead(pin, value); +``` + +The reference voltage of these pins is 3.3V. + +Pins A8, A9, A10 and A11 can not be used as GPIOs, but are limited to use as analog input pins. + +***For more advanced analog readings, you can use the `AdvancedAnalogRedux` library. Read more about this in the [Advanced ADC section](/tutorials/giga-r1-wifi/giga-audio#analog-to-digital-converters).*** + + +### PWM Pins + +PWM (Pulse Width Modulation) capability allows a digital pin to emulate analog output by flickering on and off very fast letting you, among other things, dim LEDs connected to digital pins. + +The **GIGA R1** has 12 PWM capable pins, the PWM capable pins are 2-12. You may use them as analog output pins with the function: + +```arduino +analogWrite(pin, value); +``` + +### Digital Pins + +The **GIGA R1** features more pins than any other Arduino board for makers, a full 76 digital pins. Though many of them serve another purpose and shouldn't be used for GPIO if you have other pins available. + +- 0 - RX0 +- 1 - TX0 +- 8 - SCL2 +- 9 - SDA2 +- 10 - CS +- 11 - COPI +- 12 - CIPO +- 13 - SCK +- 14 - TX3 +- 15 - RX3 +- 16 - TX2 +- 17 - RX2 +- 18 - TX1 +- 19 - RX1 +- 20 - SDA +- 21 - SCL + +The reference voltage of all digital pins is 3.3V. + +### DAC Pins + +The **GIGA R1** also has two DAC pins, A12 & A13, that can act as genuine analog output pins which means they are even more capable than PWM pins. +```arduino +analogWrite(pin, value); +``` + +![DAC Pins](assets/audio-jack.png) + +These DAC pins have a default write resolution of 8-bits. This means that values that are written to the pin should be between 0-255. + +However you may change this write resolution if you need to, to up to 12-bits: + +```arduino +analogWriteResolution(12); +``` + +***For advanced usage of the DAC, you can use the `AdvancedAnalogRedux` library. Read more about this in the [Advanced DAC section](/tutorials/giga-r1-wifi/giga-audio#digital-to-analog-converters).*** + +### OFF Pin + +On the **GIGA R1** you will find a pin labelled **"OFF"**. If you connect this pin to ground, the board will power down even if power is supplied to the board. + +You can install a flip-switch to the board to let you turn your device on and off easily, which can be a handy option for a more permanent fixture. + +## Interrupts + +If you're creating a project that relies heavily on accurate sensordata, and therefore need to ensure that you read the record any change in value, it can be difficult to write a program that does anything else well. This is because the microcontroller is busy trying to read the values constantly. To get around this you can use interrupts that can let you can be useful for reading input from for example a rotary encoder or a push button without putting any code in your loop function. + +This feature might be extra valuable to the maker with an **GIGA R1**, as their circuit gets more and more complex. + +All GPIO pins on the **GIGA R1** can be used for interrupts. + +The syntax for creating an interrupt function should be included in `void setup()` and is as follows: +```arduino +attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) +``` + +- `pin` represents the pin number of the pin your input sensor is connected to, +- `ISR` is the function that is called whenever the interrupt is triggered, and should be defined bt you somewhere in your sketch. +- `mode` defines when the interrupt should be triggered, and can be one of four pre-defined modes. + +The different modes that can be used are: +- `LOW` triggers the interrupt when the pin is low. +- `CHANGE` triggers whenever the pin changes values. +- `RISING` triggers when the pin goes from low to high. +- `FALLING` triggers when the pin goes from high to low. + +This example sketch will turn on or off an LED connected to pin 13 whenever a pushbutton connected to pin 2 is pressed or released: + +```arduino +const byte ledPin = 13; +const byte interruptPin = 2; +volatile byte state = LOW; + +void setup() { + pinMode(ledPin, OUTPUT); + pinMode(interruptPin, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE); +} + +void loop() { + digitalWrite(ledPin, state); +} + +void blink() { + state = !state; +} +``` diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/hero-banner.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/hero-banner.png new file mode 100644 index 0000000000..49b0e39b69 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/hero-banner.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/adcs.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/adcs.png new file mode 100644 index 0000000000..ac07a35311 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/adcs.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/audio-pins.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/audio-pins.png new file mode 100644 index 0000000000..f50bab027e Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/audio-pins.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/dacs-and-jack.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/dacs-and-jack.png new file mode 100644 index 0000000000..954cc261c5 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/dacs-and-jack.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-1.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-1.png new file mode 100644 index 0000000000..bcf8e4eed4 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-1.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-2.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-2.png new file mode 100644 index 0000000000..f011317de3 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-2.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-3.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-3.png new file mode 100644 index 0000000000..0db3614702 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/assets/jack-schematic-3.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/content.md b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/content.md new file mode 100644 index 0000000000..058937af88 --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/content.md @@ -0,0 +1,916 @@ +--- +title: Guide to GIGA R1 Advanced ADC/DAC and Audio Features +description: 'Learn how to use the ADC/DAC features, along with useful examples on how to generate waveforms and play audio from a file.' +author: José Bagur, Taddy Chung & Karl Söderby +tags: [ADC, DAC, Audio, USB] +--- + +In the GIGA R1, you can find the powerful STM32H747XI, a dual-core 32-bit Arm® Cortex® microcontroller from STMicroelectronics; this is the same microcontroller found in the [Portenta H7](/hardware/portenta-h7) board. + +In this guide, we will focus on the advanced ADC/DAC features, utilizing the [Arduino_AdvancedAnalog](https://github.com/arduino-libraries/Arduino_AdvancedAnalog) library. The examples found in this guide can be used to: +- Set up and read ADCs with specific parameters (resolution, sample rate, number of samples per channel, queue depth). +- Set up and write to a DAC channel with specific parameters (resolution, frequency, number of samples per channel, queue depth). +- Generate specific waveforms through input via serial commands (triangle, square, sine, sawtooth waves) as well as adjusting the frequency. +- Read and play audio files (`.wav`) from a USB stick (connected to USB-A) to a speaker, using the audio jack. + +***Important note: the GIGA R1 does NOT have an amplifying circuit onboard. Connecting speakers that does not have an amplifier can damage the DAC and the board itself.*** + +## Hardware & Software Needed + +- [GIGA R1 WiFi](/hardware/giga-r1). +- [Arduino IDE](https://www.arduino.cc/en/software) +- [Arduino_AdvancedAnalog](https://github.com/arduino-libraries/Arduino_AdvancedAnalog) library. + +And for specific examples: + +- USB Mass Storage Device (USB Stick). +- Auxiliary Cable. +- Speaker with a built-in amplifier. + +## ADC/DAC Pins and Connectors + +The GIGA gives you access to more pins than any other Arduino board accessible for makers. Many have unique features; we will focus on the pins that have audio features or can be used for developing audio applications. Audio pins and connectors in the GIGA can be divided into three important groups: + +- Analog-to-Digital Converters (ADC) pins +- Digital-to-Analog Converters (DAC) pins +- Tip, Ring, Ring, Sleeve (TRRS) 3.5mm jack + +The image below shows the position of the audio pins and connectors of the GIGA R1: + +![ADC/DAC pins and connectors of the GIGA R1](assets/audio-pins.png) + +The table below explains the full functionality of the listed on it; notice that some pins have more than one functionality, such as `DAC0`, `DAC1`, `CANRX`, and `CANTX`: + +| Pin | Functionality | +|:-----:|:--------------:| +| A0 | ADC | +| A1 | ADC | +| A2 | ADC | +| A3 | ADC | +| A4 | ADC | +| A5 | ADC | +| A6 | ADC | +| A7 | ADC | +| A8 | ADC | +| A9 | ADC | +| A10 | ADC | +| A11 | ADC | +| DAC0 | ADC and DAC | +| DAC1 | ADC and DAC | +| CANRX | ADC and CAN RX | +| CANTX | ADC and CAN TX | + +Pins `A7`, `DAC0`, and `DAC1` can also be accessed via the built-in TRRS 3.5mm jack. `DAC0` is connected to ring 1 (right channel), `DAC1` is connected to the tip (left channel), and `A7` is connected to ring 2 (microphone) of the jack, as shown in the schematic below: + +![GIGA R1 TRRS 3.5mm jack schematic](assets/jack-schematic-1.png) + +## Analog-to-Digital Converter (ADC) + +An analog-to-digital converter (ADC) is a device that converts an analog voltage, or signal, into digital data. The GIGA R1 microcontroller, the STM32H747XI, embeds three ADCs whose resolution can be configured to 8, 10, 12, 14, or 16 bits. Each ADC shares up to 20 external channels that can be accessed in the GIGA R1 board through pins `A0`, `A1`, `A2`, `A3`, `A4`, `A5`, `A6`, `A7`, `A8`, `A9`, `A10`, and `A11`; pins `DAC0`, `DAC1`, `CANRX`, and `CANTX` can also be used as ADCs. + +![ADC pins of the GIGA R1](assets/adcs.png) + +`A7` is connected to ring 2 (microphone) of the jack, as shown in the schematic below: + +![GIGA R1 3.5mm input jack schematic](assets/jack-schematic-2.png) + +The GIGA R1 ADCs can be used with the [built-in analog input/output functions of the Arduino programming language](https://www.arduino.cc/reference/de/language/functions/analog-io/analogread/), though they only provide the basic functionalities of the ADCs. To use all of the capabilities of the DACs from the GIGA R1, we can use the [Arduino_AdvancedAnalog](https://github.com/bcmi-labs/Arduino_AdvancedAnalog) library from Arduino. Let's check some interesting examples that show some capabilities of the GIGA R1 ADCs! + +### Multi Channel ADC + +The following example code show how to use two GIGA R1 ADCs simultaneously with the **Arduino_AdvancedAnalog** library from Arduino: + +```arduino +// This example shows how to use 2 ADC simultaneously. +#include + +AdvancedADC adc1(A0); +AdvancedADC adc2(A1); +uint64_t last_millis = 0; + +void setup() { + Serial.begin(9600); + + // Resolution, sample rate, number of samples per channel, queue depth. + if (!adc1.begin(AN_RESOLUTION_16, 16000, 32, 64)) { + Serial.println("Failed to start analog acquisition!"); + while (1); + } + + if (!adc2.begin(AN_RESOLUTION_16, 8000, 32, 64)) { + Serial.println("Failed to start analog acquisition!"); + while (1); + } +} + +void adc_print_buf(AdvancedADC &adc) { + if (adc.available()) { + SampleBuffer buf = adc.read(); + + // Print first sample. + Serial.println(buf[0]); + + // Release the buffer to return it to the pool. + buf.release(); + } +} + +void loop() { + if (millis() - last_millis > 1) { + adc_print_buf(adc1); + adc_print_buf(adc2); + last_millis = millis(); + } +} +``` + +### ADC Serial Plotter Example + +The following example code shows how to use two GIGA R1 ADCs simultaneously with the **Arduino_AdvancedAnalog** library from Arduino and displays the readings via the Serial Plotter of the Arduino IDE: + +```arduino +#include + +AdvancedADC adc(A0, A1); +uint64_t last_millis = 0; + +void setup() { + Serial.begin(9600); + + // Resolution, sample rate, number of samples per channel, queue depth. + if (!adc.begin(AN_RESOLUTION_16, 16000, 32, 128)) { + Serial.println("Failed to start analog acquisition!"); + while (1); + } +} + +void loop() { + if (adc.available()) { + SampleBuffer buf = adc.read(); + // Process the buffer. + if ((millis() - last_millis) > 20) { + Serial.println(buf[0]); // Sample from first channel + Serial.println(buf[1]); // Sample from second channel + last_millis = millis(); + } + // Release the buffer to return it to the pool. + buf.release(); + } +} +``` + +## Digital-to-Analog Converters (DAC) + +A digital-to-analog converter (DAC) is a device that has a function opposite to that of the analog-to-digital converter (ADC); a DAC converts digital data to an analog voltage. The GIGA R1 microcontroller, the STM32H747XI, features two 12-bit buffered DAC channels that can convert two digital signals into two analog voltage signals. Some of the features of the DACs found in the GIGA R1 are the following: + +- 8-bit or 12-bit monotonic output +- Left or right data alignment in 12-bit mode +- Dual DAC channel independent or simultaneous conversions +- DMA capability for each channel +- External triggers for conversion +- Input voltage reference or internal voltage reference +- Analog waveform generation + +The GIGA R1 DACs are named `DAC0` and `DAC1`; they can be found on pins `A12` and `A13` correspondingly, as shown in the image below: + +![DAC0, DAC1 and the 3.5mm input jack of the GIGA R1](assets/dacs-and-jack.png) + +Besides pins `A12` and `A13`, `DAC0` and `DAC1` can also be accessed via the built-in TRRS 3.5mm jack. `DAC0` is connected to the right channel (tip), while `DAC1` is connected to the left channel (ring) of the input jack as shown in the schematic below: + +![GIGA R1 3.5mm input jack schematic](assets/jack-schematic-3.png) + +### Waveform Generation with the GIGA R1 DACs + +Waveform generation is an exciting application used in audio systems, for example, synthesizers, for audio signal generation. + +The following example shows how to output an 8kHz square wave on `DAC0`: + +```arduino +// This example outputs an 8KHz square wave on A12/DAC0. +#include + +AdvancedDAC dac1(A12); + +void setup() { + Serial.begin(9600); + + while (!Serial) { + + } + + if (!dac1.begin(AN_RESOLUTION_12, 8000, 32, 64)) { + Serial.println("Failed to start DAC1 !"); + while (1); + } +} + +void dac_output_sq(AdvancedDAC &dac_out) { + if (dac_out.available()) { + + // Get a free buffer for writing. + SampleBuffer buf = dac_out.dequeue(); + + // Write data to buffer. + for (int i=0; i + +AdvancedDAC dac1(A12); +AdvancedDAC dac2(A13); + +void setup() { + Serial.begin(9600); + + while (!Serial) { + + } + + if (!dac1.begin(AN_RESOLUTION_12, 8000, 32, 64)) { + Serial.println("Failed to start DAC1 !"); + while (1); + } + + if (!dac2.begin(AN_RESOLUTION_12, 16000, 32, 64)) { + Serial.println("Failed to start DAC2 !"); + while (1); + } +} + +void dac_output_sq(AdvancedDAC &dac_out) { + if (dac_out.available()) { + + // Get a free buffer for writing. + SampleBuffer buf = dac_out.dequeue(); + + // Write data to buffer. + for (int i=0; i + +AdvancedDAC dac1(A12); + +uint16_t lut[] = { + 0x0800,0x08c8,0x098f,0x0a52,0x0b0f,0x0bc5,0x0c71,0x0d12,0x0da7,0x0e2e,0x0ea6,0x0f0d,0x0f63,0x0fa7,0x0fd8,0x0ff5, + 0x0fff,0x0ff5,0x0fd8,0x0fa7,0x0f63,0x0f0d,0x0ea6,0x0e2e,0x0da7,0x0d12,0x0c71,0x0bc5,0x0b0f,0x0a52,0x098f,0x08c8, + 0x0800,0x0737,0x0670,0x05ad,0x04f0,0x043a,0x038e,0x02ed,0x0258,0x01d1,0x0159,0x00f2,0x009c,0x0058,0x0027,0x000a, + 0x0000,0x000a,0x0027,0x0058,0x009c,0x00f2,0x0159,0x01d1,0x0258,0x02ed,0x038e,0x043a,0x04f0,0x05ad,0x0670,0x0737 +}; + +static size_t lut_size = sizeof(lut) / sizeof(lut[0]); + +void setup() { + Serial.begin(9600); + if (!dac1.begin(AN_RESOLUTION_12, 32000 * lut_size, 64, 128)) { + Serial.println("Failed to start DAC1 !"); + while (1); + } +} + +void loop() { + static size_t lut_offs = 0; + + if (dac1.available()) { + // Get a free buffer for writing. + SampleBuffer buf = dac1.dequeue(); + + // Write data to buffer. + for (size_t i=0; i + +#define N_SAMPLES (256) +#define DEFAULT_FREQUENCY (16000) + +AdvancedDAC dac1(A12); +uint8_t SAMPLES_BUFFER[N_SAMPLES]; +size_t dac_frequency = DEFAULT_FREQUENCY; + +void generate_waveform(int cmd) +{ + switch (cmd) { + case 't': + // Triangle wave + Serial.print("Waveform: Triangle "); + for (int i=0; i 1000) { + dac_frequency /= 2; + } else { + break; + } + + dac1.stop(); + delay(500); + if (!dac1.begin(AN_RESOLUTION_8, dac_frequency * N_SAMPLES, N_SAMPLES, 32)) { + Serial.println("Failed to start DAC1 !"); + } + delay(500); + break; + + default: + Serial.print("Unknown command "); + Serial.println((char) cmd); + return; + } + + Serial.print(dac_frequency/1000); + Serial.println("KHz"); +} + +void setup() { + Serial.begin(115200); + + while (!Serial) { + + } + + + Serial.println("Enter a command:"); + Serial.println("t: Triangle wave"); + Serial.println("q: Square wave"); + Serial.println("s: Sine wave"); + Serial.println("r: Sawtooth wave"); + Serial.println("+: Increase frequency"); + Serial.println("-: Decrease frequency"); + + generate_waveform('s'); + + // DAC initialization + if (!dac1.begin(AN_RESOLUTION_8, DEFAULT_FREQUENCY * N_SAMPLES, N_SAMPLES, 32)) { + Serial.println("Failed to start DAC1 !"); + while (1); + } +} + +void loop() { + if (Serial.available() > 0) { + int cmd = Serial.read(); + if (cmd != '\n') { + generate_waveform(cmd); + } + } + + if (dac1.available()) { + // Get a free buffer for writing. + SampleBuffer buf = dac1.dequeue(); + + // Write data to buffer. + for (size_t i=0; i +#include +#include +#include + +AdvancedDAC dac1(A12); + +USBHostMSD msd; +mbed::FATFileSystem usb("USB_DRIVE"); + +FILE * file = nullptr; +int sample_size = 0; +int samples_count = 0; + + +void setup() +{ + Serial.begin(115200); + while (!Serial); + + /* Enable power for HOST USB connector. */ + pinMode(PA_15, OUTPUT); + digitalWrite(PA_15, HIGH); + + Serial.println("Please connect a USB stick to the GIGA's USB port ..."); + while (!msd.connect()) delay(100); + + Serial.println("Mounting USB device ..."); + int const rc_mount = usb.mount(&msd); + if (rc_mount) + { + Serial.print("Error mounting USB device "); + Serial.println(rc_mount); + return; + } + + Serial.println("Opening audio file ..."); + + /* 16-bit PCM Mono 16kHz realigned noise reduction */ + file = fopen("/USB_DRIVE/AUDIO_SAMPLE.wav", "rb"); + if (file == nullptr) + { + Serial.print("Error opening audio file: "); + Serial.println(strerror(errno)); + return; + } + + Serial.println("Reading audio header ..."); + struct wav_header_t + { + char chunkID[4]; //"RIFF" = 0x46464952 + unsigned long chunkSize; //28 [+ sizeof(wExtraFormatBytes) + wExtraFormatBytes] + sum(sizeof(chunk.id) + sizeof(chunk.size) + chunk.size) + char format[4]; //"WAVE" = 0x45564157 + char subchunk1ID[4]; //"fmt " = 0x20746D66 + unsigned long subchunk1Size; //16 [+ sizeof(wExtraFormatBytes) + wExtraFormatBytes] + unsigned short audioFormat; + unsigned short numChannels; + unsigned long sampleRate; + unsigned long byteRate; + unsigned short blockAlign; + unsigned short bitsPerSample; + }; + + wav_header_t header; + fread(&header, sizeof(header), 1, file); + + Serial.println("WAV File Header read:"); + char msg[64] = {0}; + snprintf(msg, sizeof(msg), "File Type: %s", header.chunkID); + Serial.println(msg); + snprintf(msg, sizeof(msg), "File Size: %ld", header.chunkSize); + Serial.println(msg); + snprintf(msg, sizeof(msg), "WAV Marker: %s", header.format); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Format Name: %s", header.subchunk1ID); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Format Length: %ld", header.subchunk1Size); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Format Type: %hd", header.audioFormat); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Number of Channels: %hd", header.numChannels); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Sample Rate: %ld", header.sampleRate); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Sample Rate * Bits/Sample * Channels / 8: %ld", header.byteRate); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Bits per Sample * Channels / 8: %hd", header.blockAlign); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Bits per Sample: %hd", header.bitsPerSample); + Serial.println(msg); + + /* Find the data section of the WAV file. */ + struct chunk_t + { + char ID[4]; + unsigned long size; + }; + + chunk_t chunk; + snprintf(msg, sizeof(msg), "id\t" "size"); + Serial.println(msg); + /* Find data chunk. */ + while (true) + { + fread(&chunk, sizeof(chunk), 1, file); + snprintf(msg, sizeof(msg), "%c%c%c%c\t" "%li", chunk.ID[0], chunk.ID[1], chunk.ID[2], chunk.ID[3], chunk.size); + Serial.println(msg); + if (*(unsigned int *) &chunk.ID == 0x61746164) + break; + /* Skip chunk data bytes. */ + fseek(file, chunk.size, SEEK_CUR); + } + + /* Determine number of samples. */ + sample_size = header.bitsPerSample / 8; + samples_count = chunk.size * 8 / header.bitsPerSample; + snprintf(msg, sizeof(msg), "Sample size = %i", sample_size); Serial.println(msg); + snprintf(msg, sizeof(msg), "Samples count = %i", samples_count); Serial.println(msg); + + /* Configure the advanced DAC. */ + if (!dac1.begin(AN_RESOLUTION_12, header.sampleRate, 256, 16)) + { + Serial.println("Failed to start DAC1 !"); + return; + } +} + +void loop() +{ + if (dac1.available() && !feof(file)) + { + /* Read data from file. */ + uint16_t sample_data[256] = {0}; + fread(sample_data, sample_size, 256, file); + + /* Get a free buffer for writing. */ + SampleBuffer buf = dac1.dequeue(); + + /* Write data to buffer. */ + for (size_t i = 0; i < buf.size(); i++) + { + /* Scale down to 12 bit. */ + uint16_t const dac_val = ((static_cast(sample_data[i])+32768)>>4) & 0x0fff; + buf[i] = dac_val; + } + + /* Write the buffer to DAC. */ + dac1.write(buf); + } +} +``` + +### Loop Multiple Audio Files + +This example is similar to the **Play Single Audio File** example, but with some key changes: + +- This example uses multiple audio files. +- The file read is moved to a separate function, `configFile()`, as it will be continuously called from the sketch. +- Instead of playing a file once, it keeps looping it. +- The **BOOT0** (`PC_13`) button (right next to the audio jack) is used as a regular pushbutton to loop through the audio files. +- Pressing the button changes the file played. + +The files used are called `DRUM.wav`, `WARP.wav`, `BASS.wav` and `SHAKE.wav`. They are very short (around 1 second). These needs to be present on the USB stick used. + +You can download them from [this link](/resources/misc/giga_audio_examples.zip). + +```arduino +/* + * GIGA R1 - Audio Playback + * Simple wav format audio playback via 12-Bit DAC output by reading from a USB drive. + * In order for this sketch to work you need to rename 'USB_DRIVE' to the name of your USB stick drive. + * Furthermore you need to store the provided audio file AUDIO_SAMPLE.wav on it. +*/ + +#include +#include +#include +#include + +AdvancedDAC dac1(A12); + +USBHostMSD msd; +mbed::FATFileSystem usb("usb"); + +FILE *file = nullptr; +int sample_size = 0; +int samples_count = 0; + +int swapFile; + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + /* Enable power for HOST USB connector. */ + + pinMode(PA_15, OUTPUT); + digitalWrite(PA_15, HIGH); + + Serial.println("Please connect a USB stick to the GIGA's USB port ..."); + while (!msd.connect()) delay(100); + + Serial.println("Mounting USB device ..."); + int const rc_mount = usb.mount(&msd); + if (rc_mount) { + Serial.print("Error mounting USB device "); + Serial.println(rc_mount); + return; + } + configFile(); +} + +void loop() { + if (dac1.available() && !feof(file)) { + /* Read data from file. */ + uint16_t sample_data[256] = { 0 }; + fread(sample_data, sample_size, 256, file); + + /* Get a free buffer for writing. */ + SampleBuffer buf = dac1.dequeue(); + + /* Write data to buffer. */ + for (size_t i = 0; i < buf.size(); i++) { + /* Scale down to 12 bit. */ + uint16_t const dac_val = ((static_cast(sample_data[i]) + 32768) >> 4) & 0x0fff; + buf[i] = dac_val; + } + + /* Write the buffer to DAC. */ + dac1.write(buf); + + if(feof(file)){ + fclose(file); + configFile(); + } + } + + int buttonState = digitalRead(PC_13); + + if (buttonState == 1) { + swapFile = swapFile + 1; + if (swapFile == 4) { + swapFile = 0; + } + delay(500); + configFile(); + } +} + + +void configFile() { + Serial.println("Opening audio file ..."); + + /* 16-bit PCM Mono 16kHz realigned noise reduction */ + if (swapFile == 0) { + file = fopen("/usb/DRUM.wav", "rb"); + } else if (swapFile == 1) { + file = fopen("/usb/WARP.wav", "rb"); + } else if (swapFile == 2) { + file = fopen("/usb/BASS.wav", "rb"); + } else if (swapFile == 3) { + file = fopen("/usb/SHAKE.wav", "rb"); + } + + if (file == nullptr) { + Serial.print("Error opening audio file: "); + Serial.println(strerror(errno)); + return; + } + + Serial.println("Reading audio header ..."); + struct wav_header_t { + char chunkID[4]; //"RIFF" = 0x46464952 + unsigned long chunkSize; //28 [+ sizeof(wExtraFormatBytes) + wExtraFormatBytes] + sum(sizeof(chunk.id) + sizeof(chunk.size) + chunk.size) + char format[4]; //"WAVE" = 0x45564157 + char subchunk1ID[4]; //"fmt " = 0x20746D66 + unsigned long subchunk1Size; //16 [+ sizeof(wExtraFormatBytes) + wExtraFormatBytes] + unsigned short audioFormat; + unsigned short numChannels; + unsigned long sampleRate; + unsigned long byteRate; + unsigned short blockAlign; + unsigned short bitsPerSample; + }; + + wav_header_t header; + fread(&header, sizeof(header), 1, file); + + Serial.println("WAV File Header read:"); + char msg[64] = { 0 }; + snprintf(msg, sizeof(msg), "File Type: %s", header.chunkID); + Serial.println(msg); + snprintf(msg, sizeof(msg), "File Size: %ld", header.chunkSize); + Serial.println(msg); + snprintf(msg, sizeof(msg), "WAV Marker: %s", header.format); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Format Name: %s", header.subchunk1ID); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Format Length: %ld", header.subchunk1Size); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Format Type: %hd", header.audioFormat); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Number of Channels: %hd", header.numChannels); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Sample Rate: %ld", header.sampleRate); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Sample Rate * Bits/Sample * Channels / 8: %ld", header.byteRate); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Bits per Sample * Channels / 8: %hd", header.blockAlign); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Bits per Sample: %hd", header.bitsPerSample); + Serial.println(msg); + + /* Find the data section of the WAV file. */ + struct chunk_t { + char ID[4]; + unsigned long size; + }; + + chunk_t chunk; + snprintf(msg, sizeof(msg), "id\t" + "size"); + Serial.println(msg); + /* Find data chunk. */ + while (true) { + fread(&chunk, sizeof(chunk), 1, file); + snprintf(msg, sizeof(msg), "%c%c%c%c\t" + "%li", + chunk.ID[0], chunk.ID[1], chunk.ID[2], chunk.ID[3], chunk.size); + Serial.println(msg); + if (*(unsigned int *)&chunk.ID == 0x61746164) + break; + /* Skip chunk data bytes. */ + fseek(file, chunk.size, SEEK_CUR); + } + + /* Determine number of samples. */ + sample_size = header.bitsPerSample / 8; + samples_count = chunk.size * 8 / header.bitsPerSample; + snprintf(msg, sizeof(msg), "Sample size = %i", sample_size); + Serial.println(msg); + snprintf(msg, sizeof(msg), "Samples count = %i", samples_count); + Serial.println(msg); + + /* Configure the advanced DAC. */ + if (!dac1.begin(AN_RESOLUTION_12, header.sampleRate, 256, 16)) { + Serial.println("Failed to start DAC1 !"); + return; + } +} +``` + +## Pulse Density Modulation Support + +Pulse Density Support (PDM) is a form of modulation used to represent analog information into digital information; PDM uses a high-frequency stream of 1-bit digital samples. In PDM, a large cluster of ones represents a positive amplitude, while a large cluster of zeros represents a negative amplitude. + +The GIGA R1 PDM support can be used with the [built-in PDM library](https://docs.arduino.cc/learn/built-in-libraries/pdm). Let's check an interesting example that shows of how to read a PDM microphone wwith the GIGA R1: + +```arduino +#include + +// Default number of output channels +static const char channels = 1; + +// Default PCM output frequency +static const int frequency = 16000; + +// Buffer to read samples into, each sample is 16-bits +short sampleBuffer[128]; + +// Number of audio samples read +volatile int samplesRead; + +void setup() { + Serial.begin(9600); + while (!Serial); + + // Configure the callback function and gain + PDM.onReceive(onPDMdata); + PDM.setGain(30); + + // Initialize PDM microphone in mono mode, and a 16 kHz sample rate: + if (!PDM.begin(channels, frequency)) { + Serial.println("Failed to start PDM!"); + while (1); + } +} + +void loop() { + // Wait for samples to be read + if (samplesRead) { + + // Print samples to the Serial Monitor + for (int i = 0; i < samplesRead; i++) { + if(channels == 2) { + Serial.print("L:"); + Serial.print(sampleBuffer[i]); + Serial.print(" R:"); + i++; + } + Serial.println(sampleBuffer[i]); + } + + samplesRead = 0; + } +} + +// Callback function +void onPDMdata() { + int bytesAvailable = PDM.available(); + PDM.read(sampleBuffer, bytesAvailable); + samplesRead = bytesAvailable / 2; +} +``` \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/hero-banner.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/hero-banner.png new file mode 100644 index 0000000000..8d013f9732 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-audio/hero-banner.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-photo.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-photo.png new file mode 100644 index 0000000000..c981be4840 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-photo.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-pins.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-pins.png new file mode 100644 index 0000000000..d90befb4fe Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-pins.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-zoomed.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-zoomed.png new file mode 100644 index 0000000000..4a8c38fb2e Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-connector-zoomed.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-schematic.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-schematic.png new file mode 100644 index 0000000000..af99ba8448 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/camera-schematic.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/processing-example.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/processing-example.png new file mode 100644 index 0000000000..b0b8c0eafe Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/assets/processing-example.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/giga-camera.md b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/giga-camera.md new file mode 100644 index 0000000000..cb06295e8c --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/giga-camera.md @@ -0,0 +1,291 @@ +--- +title: GIGA R1 Camera Guide +description: Learn about the GIGA R1 WiFi's camera connector, and how to use existing examples. +tags: [ArduCAM, Camera, Processing] +author: Karl Söderby +--- + +The GIGA R1 has a dedicated camera connector that allows certain camera modules to mount directly on the board. This makes it possible to add machine vision to your GIGA R1 board without much effort at all. + +In this guide, we will explore the following: + +- Where the camera connector is located. +- What cameras are compatible. +- What library to use. +- How to setup a camera stream to a processing application. + +## Hardware & Software Needed + +To follow and use the examples provided in this guide, you will need an [Arduino GIGA R1 WiFi](/hardware/giga-r1-wifi) + +You will also need the following software: +- [Arduino IDE](https://www.arduino.cc/en/software) (any version). +- [Processing](https://processing.org/download) (for displaying camera feed). + +## Supported Cameras + +The GIGA R1 currently supports the following cameras, via the [Camera](https://github.com/arduino/ArduinoCore-mbed/tree/master/libraries/Camera) library that is bundled with the [Arduino Mbed Core](https://github.com/arduino/ArduinoCore-mbed): + +- **OV7670** and **OV7675** +- **GC2145** +- **Himax HM01B0** +- **Himax HM0360** + +## Camera Connector + +![Camera Connector on GIGA R1](assets/camera-connector-pins.png) + +The 20 pin camera connector onboard the GIGA R1 is designed to be directly compatible with some breakout boards from ArduCam. + +This allows you to simply connect the camera module directly to the board, without making any additional circuit. + +![Camera Module Connected](assets/camera-connector-photo.png) + +Some of the 20 pin connector breakout boards from ArduCam can be found [here](https://www.arducam.com/product-category/stm32-camera-modules-dcmi-and-spi/). + +The complete pin map can be found below: + +| Left | Right | +| ---- | ----- | +| 3V3 | GND | +| SCL1 | SDA1 | +| 54 | 55 | +| 56 | 57 | +| 58 | 59 | +| 60 | 61 | +| 62 | 63 | +| 64 | 65 | +| 66 | 67 | +| 66 | 67 | + +![Camera connector, zoomed in.](assets/camera-connector-zoomed.png) + +You can also view the schematic for this connector in more detail just below. This is useful to understand exactly which pins on the STM32H747XI microcontroller is used. + +![Schematic for Camera Connector (J6).](assets/camera-schematic.png) + +## Raw Bytes Over Serial (Processing) + +![Live view of the camera.](assets/processing-example.png) + +This example allows you to stream the sensor data from your camera to a Processing application, using serial over USB. This will allow you to see the image directly in your computer. + +***This example requires a version of [Processing](https://processing.org/download) on your machine.*** + +### Step 1: Arduino + +Upload the following sketch to your board. + +This sketch is also available in the Arduino IDE via **Examples > Camera > CameraCaptureRawBytes**. + +```arduino +#include "camera.h" + +#ifdef ARDUINO_NICLA_VISION + #include "gc2145.h" + GC2145 galaxyCore; + Camera cam(galaxyCore); + #define IMAGE_MODE CAMERA_RGB565 +#elif defined(ARDUINO_PORTENTA_H7_M7) + #include "hm0360.h" + HM0360 himax; + Camera cam(himax); + #define IMAGE_MODE CAMERA_GRAYSCALE +#elif defined(ARDUINO_GIGA) + #include "ov7670.h" + OV7670 ov7670; + Camera cam(ov7670); + #define IMAGE_MODE CAMERA_RGB565 +#else +#error "This board is unsupported." +#endif + +/* +Other buffer instantiation options: + FrameBuffer fb(0x30000000); + FrameBuffer fb(320,240,2); +*/ +FrameBuffer fb; + +unsigned long lastUpdate = 0; + + +void blinkLED(uint32_t count = 0xFFFFFFFF) +{ + pinMode(LED_BUILTIN, OUTPUT); + while (count--) { + digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level) + delay(50); // wait for a second + digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW + delay(50); // wait for a second + } +} + +void setup() { + // Init the cam QVGA, 30FPS + if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) { + blinkLED(); + } + + blinkLED(5); +} + +void loop() { + if(!Serial) { + Serial.begin(921600); + while(!Serial); + } + + // Time out after 2 seconds and send new data + bool timeoutDetected = millis() - lastUpdate > 2000; + + // Wait for sync byte. + if(!timeoutDetected && Serial.read() != 1) return; + + lastUpdate = millis(); + + // Grab frame and write to serial + if (cam.grabFrame(fb, 3000) == 0) { + Serial.write(fb.getBuffer(), cam.frameSize()); + } else { + blinkLED(20); + } +} + +``` + +### Step 2: Processing + +The following Processing sketch will launch a Java app that allows you to view the camera feed. As data is streamed via serial, make sure you close the Serial Monitor during this process, else it will not work. + +***Important! Make sure to replace the following line in the code below: `/dev/cu.usbmodem14301`, with the name of your port.*** + +Click on the **"PLAY"** button to initialize the app. + +```cpp +/* + Use with the Examples -> CameraCaptureRawBytes Arduino sketch. + This example code is in the public domain. +*/ + +import processing.serial.*; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +Serial myPort; + +// must match resolution used in the Arduino sketch +final int cameraWidth = 320; +final int cameraHeight = 240; + +// Must match the image mode in the Arduino sketch +final boolean useGrayScale = true; + +// Must match the baud rate in the Arduino sketch +final int baudRate = 921600; + +final int cameraBytesPerPixel = useGrayScale ? 1 : 2; +final int cameraPixelCount = cameraWidth * cameraHeight; +final int bytesPerFrame = cameraPixelCount * cameraBytesPerPixel; +final int timeout = int((bytesPerFrame / float(baudRate / 10)) * 1000 * 2); // Twice the transfer rate + +PImage myImage; +byte[] frameBuffer = new byte[bytesPerFrame]; +int lastUpdate = 0; +boolean shouldRedraw = false; + +void setup() { + size(640, 480); + + // If you have only ONE serial port active you may use this: + //myPort = new Serial(this, Serial.list()[0], baudRate); // if you have only ONE serial port active + + // If you know the serial port name + //myPort = new Serial(this, "COM5", baudRate); // Windows + //myPort = new Serial(this, "/dev/ttyACM0", baudRate); // Linux + myPort = new Serial(this, "/dev/cu.usbmodem14301", baudRate); // Mac + + // wait for a full frame of bytes + myPort.buffer(bytesPerFrame); + + myImage = createImage(cameraWidth, cameraHeight, ALPHA); + + // Let the Arduino sketch know we're ready to receive data + myPort.write(1); +} + +void draw() { + // Time out after a few seconds and ask for new data + if(millis() - lastUpdate > timeout) { + println("Connection timed out."); + myPort.clear(); + myPort.write(1); + } + + if(shouldRedraw){ + PImage img = myImage.copy(); + img.resize(640, 480); + image(img, 0, 0); + shouldRedraw = false; + } +} + +int[] convertRGB565ToRGB888(short pixelValue){ + //RGB565 + int r = (pixelValue >> (6+5)) & 0x01F; + int g = (pixelValue >> 5) & 0x03F; + int b = (pixelValue) & 0x01F; + //RGB888 - amplify + r <<= 3; + g <<= 2; + b <<= 3; + return new int[]{r,g,b}; +} + +void serialEvent(Serial myPort) { + lastUpdate = millis(); + + // read the received bytes + myPort.readBytes(frameBuffer); + + // Access raw bytes via byte buffer + ByteBuffer bb = ByteBuffer.wrap(frameBuffer); + + // Ensure proper endianness of the data for > 8 bit values. + // The 1 byte bb.get() function will always return the bytes in the correct order. + bb.order(ByteOrder.BIG_ENDIAN); + + int i = 0; + + while (bb.hasRemaining()) { + if(useGrayScale){ + // read 8-bit pixel data + byte pixelValue = bb.get(); + + // set pixel color + myImage.pixels[i++] = color(Byte.toUnsignedInt(pixelValue)); + } else { + // read 16-bit pixel data + int[] rgbValues = convertRGB565ToRGB888(bb.getShort()); + + // set pixel RGB color + myImage.pixels[i++] = color(rgbValues[0], rgbValues[1], rgbValues[2]); + } + } + + myImage.updatePixels(); + + // Ensures that the new image data is drawn in the next draw loop + shouldRedraw = true; + + // Let the Arduino sketch know we received all pixels + // and are ready for the next frame + myPort.write(1); +} +``` + +If all goes well, you should now be able to see the camera feed. + +## Summary + +In this article, we learned a bit more about the camera connector on board the GIGA R1 board, how it is connected to the STM32H747XI microcontroller, and a simple example on how to connect an inexpensive OV7675 camera module to a Processing application. \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/hero-banner.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/hero-banner.png new file mode 100644 index 0000000000..6119f3b054 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-camera/hero-banner.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/assets/flash-split.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/assets/flash-split.png new file mode 100644 index 0000000000..624394effe Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/assets/flash-split.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/assets/target-core.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/assets/target-core.png new file mode 100644 index 0000000000..33e3cad617 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/assets/target-core.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md new file mode 100644 index 0000000000..8ba305c72e --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md @@ -0,0 +1,215 @@ +--- +title: Guide to GIGA R1 Dual Cores +description: Learn how to access and control the M4 and M7 cores on the GIGA R1 +author: Karl Söderby +tags: [Dual Core, M4, M7] +--- + +The GIGA R1's [STM32H747XI](static/resources/datasheets/stm32h747xi.pdf) has two cores, the M4 and the M7. Each core can be programmed individually, with M7 acting as the main processor, and the M4 as a co-processor. + +The M7 is referred to as the main processor due its superior hardware features, as well as it is required to run to boot the M4 core (you boot the M4 from within the M7). + +These two cores can run applications in parallel, for example, running a servo motor on one core, and a display on another, without blocking each other. In a single core, such operations would slow down the program, resulting in lesser performance. + +The M4 and M7 cores are programmed with separate sketches, using the same serial port. In the Arduino IDE, you can select the core you want to program, and then upload the sketch you want to run on that specific core. + +## Hardware & Software Needed + +- [GIGA R1 WiFi](/hardware/giga-r1-wifi) +- [Arduino IDE](https://www.arduino.cc/en/software) +- Arduino GIGA Core installed.\* + +***\*For instructions on how to install the GIGA Core, follow the [Getting Started with GIGA R1 guide](/tutorials/giga-r1-wifi/giga-getting-started).*** + +## Programming M4/M7 + +Programming the cores is done via the Arduino IDE, in a special interface that appears only when you **select the Arduino GIGA R1 board** from the board menu. + +### Partitioning The Flash Memory + +To allocate memory for the M4, the flash memory can be partitioned. This is done by navigating to **Tools > Flash Split** in the IDE. + +![Flash partitioning in the IDE.](assets/flash-split.png) + +- **2MB M7 + M4 in SDRAM (default)** - this option is the default configuration, which is for programming the M7 only. This allocates no memory to the M4. +- **1.5MB M7 + 0.5MB M4** - useful when larger amount of memory is required on the M7. +- **1MB M7 + 1MB M4** - useful when you need to balance the memory equally between the M4 and M7 cores. + +***It is required to use option 2 or 3 if you intend to program the M4 via the IDE, as the default option provides no memory allocation for the M4.*** + +### Target Core + +To select the core you want to program, navigate to **Tools > Target Core** in the IDE. + +![Flash partitioning in the IDE.](assets/target-core.png) + +Here you can choose between: +- **Main Core** - this is the M7 core, the main processor on the board. +- **M4 Co-processor** - this is the M4 core, the co-processor on the board. + +### Uploading + +As both cores share the same serial port, choosing the **Flash Split** + **Target Core** is required so that the program is uploaded to the correct core. + +Uploading is no different than to any other Arduino board: simply click the upload button and wait for it to finish. + +### Booting M4 Core + +The M4 core does not boot by itself as it requires interaction from the M7 core. This boot function is built into the `RPC` library, and needs to be included in the sketch uploaded to the M7: + +```arduino +#include + +void setup() { + RPC.begin(); //boots M4 +} +void loop(){ +} +``` + +Once the M4 is booted from the M7, both cores will run in parallel, much like two Arduinos sharing the same board. + +### Writing Over Existing Sketch + +Uploading new sketches works the same as a typical upload procedure. The new sketch will overwrite the current sketch running on the core you upload to. + +## Limitations + +The M7 and M4 cores are two separate cores, and when initialized, they will continue to execute their corresponding program. + +In this section you will find some known limitations of using the two parallel cores. + +### Booting M4 + +As mentioned in the previous section, the M4 requires to be booted from the M7, by using the `RPC.begin()` method. If this is not included, the M4 will not boot. + +### Serial Communication + +Serial communication is not available by default on the M4 core. A work around for this is by sending data using the `RPC` library, and printing it from the M7 core. To achieve this, see the following examples: + +**M4 Sketch** + +```arduino +#include + +void setup() { + RPC.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + RPC.println("Hello World!"); +} +``` + +**M7 Sketch** + +```arduino +#include + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + RPC.begin(); +} + +void loop() { + String buffer = ""; + while (RPC.available()) { + buffer += (char)RPC.read(); + } + + if (buffer.length() > 0) { + Serial.print(buffer); + } +} +``` + +***Note that both of these sketches needs to be uploaded to their corresponding cores.*** + +### Advanced DAC/ADC On M4 + +The advanced DAC/ADC features using the [Arduino_AdvancedAnalog](https://github.com/bcmi-labs/Arduino_AdvancedAnalog/tree/main/examples/Advanced) library is not available on the M4. + +## Methods of Programming + +Programming the M4 and M7 cores is straightforward, but can be complicated to track. Having a strategy for how you want to build your dual core applications is key. + +In this section we introduce the "single" and "multiple" sketch approach, and the pros and cons of each method. + +### Single Sketch Approach + +The single sketch approach means writing a single sketch that is **uploaded to both cores** each time a change is made. In the sketch, we can keep track of what each core does by using simply by querying the core used with a simple function: + +```arduino +String currentCPU() { + if (HAL_GetCurrentCPUID() == CM7_CPUID) { + return "M7"; + } else { + return "M4"; + } +} +``` + +With this function, we check whether the M4 or M7 is running, and we can write code for each of the core like this: + +```arduino + if (currentCPU() == "M4") { + //run M4 code + } + + if (currentCPU() == "M7") { + //run M7 code + } +``` + +The pros of using this approach is that you can write all code in a single file, therefore, revisioning code, as well as the provisioning is easier to manage. + +The cons of using this approach is that you will run out of program memory faster. You will also upload code to the cores that will never execute (the M7 code will not execute on M4 and vice versa). + +### Multiple Sketch Approach + +The multiple sketch approach means developing two separate sketches, one for each core. This does not require the use of the `HAL_GetCurrentCPUID()` to retrieve what core you are using, you can instead just write the sketch as you would normally do. + +The pros of using this approach is that the code you write is optimized only for one core, and this saves a lot of program memory. + +The cons is to manage the versions becomes harder, and while flashing the board, you'd need to keep track on which version is uploaded to which core. It is easier to upload to the wrong core by accident using this approach, but you have more optimized code. + +## Use Cases + +There are a number of cases where running two cores in parallel brings an advantage. Mainly, it allows one to develop code to run simultaneously, each performing their own individual tasks. + +In all modern computers, including yours, you have several cores each occupied with a number of task, in order to speed things up. This is particularly useful in blocking operations such as: +- Controlling a servo motor, +- Loading a display, +- Connecting to a network. + +### Choosing Core + +Simply speaking, the M7 should always run your main program, or the most intensive program. It is overall a faster processor that reads memory and executes instructions faster. + +For example, you should be running network applications on the M7, while you do sensor readings on the M4. + +***To get a more detailed view on the differences between M4 and M7, see [Arm Cortex-M Processor Comparison Table](https://developer.arm.com/documentation/102787/latest).*** + +### Wi-Fi / Bluetooth® + +Wi-Fi and Bluetooth® applications are best run on the M7, as they are more demanding. Lower level tasks, such as controlling relays, reading sensor data and so forth, can be distributed to the M4 core instead. + +### Displays + +As the M7 is faster, it is best to run display sketches on the M7 core. Displays have a lot of blocking operations, and it is a good idea to separate the display's functionalities and other operations we want to perform. + +Running the display application on the M7 leaves the M4 free for other applications, such as motor control. Particularly useful when building projects where you need to control a motor from a display. + +### Robotics + +For robotics projects, separating the motor control **between the cores** can be beneficial. For example, servo control is a blocking operation, so if you are running several servos at the same time, performance can be reduced. + +It can also be distributed so that one core handles servo motors, and one handles stepper motors, if you are using multiple types of motors. + +### Sensors + +Sensor readings in itself does not matter much which core you use. If you are simply running some tests, it is good to run it on the M7, as you are able to print the results using `Serial.print()` (not available on M4, only through RPC). + +When used in relation to a e.g. a display, it is good practice to read sensors on the M4 core and on the M7, fetch the result and display it. \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/hero-banner.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/hero-banner.png new file mode 100644 index 0000000000..1c74a9b115 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/hero-banner.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/giga-connected.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/giga-connected.png new file mode 100644 index 0000000000..06c160d095 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/giga-connected.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/giga-examples.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/giga-examples.png new file mode 100644 index 0000000000..b204285cec Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/giga-examples.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/install-giga-core.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/install-giga-core.png new file mode 100644 index 0000000000..bcc1acbf05 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/install-giga-core.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/open-ide.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/open-ide.png new file mode 100644 index 0000000000..f49bc79d2f Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/assets/open-ide.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/giga-getting-started.md b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/giga-getting-started.md new file mode 100644 index 0000000000..54655a9593 --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/giga-getting-started.md @@ -0,0 +1,53 @@ +--- +title: Getting Started with GIGA R1 WiFi +description: A step-by-step guide to install the board package needed for the GIGA R1 WiFi board. +author: Karl Söderby +tags: [GIGA R1 WiFi, Installation, IDE] +--- + +To use the [Arduino GIGA R1 WiFi](/hardware/giga-r1-wifi) board, you will need to install the GIGA board package, which is part of the [Arduino Core for mbed devices](https://github.com/arduino/ArduinoCore-mbed). + +To install it, you will need a version of the Arduino IDE, which you can download from the [Arduino Software page](). In this guide, we will use the latest version of the IDE (2.0.x). + +## Software & Hardware Needed + +- [Arduino GIGA R1 WiFi](/hardware/giga-r1-wifi) +- [Arduino IDE](https://docs.arduino.cc/software/ide-v2) + +***You can also use the [Web Editor](https://create.arduino.cc/editor) which comes with all Arduino boards pre-installed.*** + +## Download & Install IDE + +1. First, we need to download the Arduino IDE, which can be done from the [Arduino Software page](https://www.arduino.cc/en/software/). +2. Install the Arduino IDE on your local machine. +3. Open the Arduino IDE. + +![The Arduino IDE.](assets/open-ide.png) + +## Install Board Package + +To install the GIGA board package, open the "Board Manager" from the menu to the left. Search for **"GIGA"** and install the latest version (or the version you want to use). + +![Install GIGA boards package.](assets/install-giga-core.png) + +You should now be able to select your board in the board selector. You will need to have your board connected to your computer via the USB-C connector at this point. + +![Arduino GIGA board found.](assets/giga-connected.png) + +Congratulations, you have now successfully installed the GIGA board package via the Arduino IDE. + +## Compile & Upload Sketches + +To compile and upload sketches, you can use the: +- **Checkmark** for compiling code. +- **Right arrow** to upload code. + +There are several examples available for the GIGA R1 board, which can be accessed directly in the IDE, through **File > Examples**. These examples can be used directly without external libraries. + +![GIGA examples.](assets/giga-examples.png) + +## Summary + +In this tutorial, we have installed the GIGA board package, using the Arduino IDE. + +For any issues regarding the GIGA board package, please refer to the [Arduino Core for mbed devices](https://github.com/arduino/ArduinoCore-mbed). diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/hero-banner.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/hero-banner.png new file mode 100644 index 0000000000..c0dc838627 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/hero-banner.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/assets/giga-main-boot.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/assets/giga-main-boot.png new file mode 100644 index 0000000000..2cf3bfa1b0 Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/assets/giga-main-boot.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/assets/giga-msd.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/assets/giga-msd.png new file mode 100644 index 0000000000..d23d6204ba Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/assets/giga-msd.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md new file mode 100644 index 0000000000..e49f6014e6 --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md @@ -0,0 +1,205 @@ +--- +title: MicroPython on the GIGA R1 +description: Get started with MicroPython on the GIGA R1. +author: Karl Söderby +tags: [MicroPython, dfu-util] +--- + +***Please note that MicroPython support for the GIGA R1 is currently in an experimental phase.*** + +***To learn more about MicroPython, please visit [MicroPython with Arduino](/learn/programming/arduino-and-python). This article is specific only to the GIGA R1 board.*** + +[MicroPython](https://micropython.org/) is an implementation of Python in a *micro* format. It can be installed on the GIGA R1, where instead of compiling and uploading sketches, the board has a built-in interpreter that converts Python code to machine code in runtime. + +This makes it possible to load various scripts instantly on the board, without the need of compiling the code, which is a great advantage of MicroPython. + +In this article, we will guide you through the installation steps, as well as some cool tips and tricks to get creative with MicroPython on the GIGA R1. + +## Hardware & Software Needed + +To follow along with this guide, you will need an [Arduino GIGA R1 WiFi](/hardware/giga-r1-wifi) + +You will need the following software/tools installed: +- [dfu-util](https://dfu-util.sourceforge.net/)\* +- An editor with support for MicroPython (such as [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython) or [Thonny](https://thonny.org/)) +- This specific [GIGAR1_MP_FW.dfu](/resources/firmware/GIGAR1_MP_FW.dfu) firmware. + +***\*The installation for `dfu-util` varies between operation systems. For installation using [brew.sh](https://formulae.brew.sh/formula/dfu-util) simply use `brew install dfu-util`.*** + +## Installation + +**1.** Download the [GIGAR1_MP_FW.dfu](/resources/firmware/GIGAR1_MP_FW.dfu) firmware. + +**2.** Download the [dfu-util](https://dfu-util.sourceforge.net/) tool, or install via Brew (or other package managers). Make sure it is in your PATH. + +``` +$ brew install dfu-util +``` + +**3.** Double tap the reset button on the GIGA R1 board. The green LED should now be pulsing. This means it is in bootloader mode. + +**4.** Open a terminal, and navigate to the directory of your `GIGAR1_MP_FW.dfu` file. Run the following command: + +``` +$ dfu-util -w -a 0 -d 2341:0366 -D GIGAR1_MP_FW.dfu +``` + +At the end of the process, you will see the following message on success: + +``` +Done parsing DfuSe file +``` + +**5.** Reset the board by clicking the reset button (just once). You should now be able to view and access some of the GIGA R1 boards onboard storage as a mass storage device in your file manager. + +![GIGA R1 mass storage.](assets/giga-msd.png) + +Congratulations! You have now installed MicroPython on the GIGA R1 board. + +## Programming Your Board + +To program your GIGA R1 with MicroPython, you will need an editor with support for MicroPython (such as [Arduino Lab for MicroPython](https://labs.arduino.cc/en/labs/micropython) or [Thonny](https://thonny.org/)). + +The editors listed above are great for getting things to work quickly. One important aspect is that in the editor, you will need to **connect to your board**, as this will make it possible to load scripts. + +As the MicroPython installation has a built-in interpreter, in the editor, you can just write a script and click on the **Run Script** button, and if it compiles, it will load almost instantly. You can make sure it works by running something simple, such as: + +```python +print("Hello world!") +``` + +If it is printed in the REPL, it means it works, and you're ready to take on bigger challenges! + +To find out examples and more fundamental knowledge, please visit the [MicroPython with Arduino documentation](/learn/programming/arduino-and-python). Here you will find an introduction to this environment and useful examples to get started. + +***It is important to note that different Arduino boards have different implementations. This is mainly due to what microcontroller the board is based on. For example, to access digital pin 2, on the GIGA R1, you will need to use `'PA3'` (with the quotation marks). See more in [GIGA R1 Pin Map](#pin-map)*** + +## Main.py + +## File System (Mass Storage) + +The MicroPython installation exposes the mass storage device on your board, which can be edited directly from your computer. This allows you to install modules, edit the boot & main script as well as adding the possibility of switching between scripts. + +### Boot & Main Scripts + +![GIGA R1's boot.py and main.py](assets/giga-main-boot.png) + +You will notice that in the mass storage device, there's two `.py` files: `boot.py` and `main.py`. + +- `boot.py` - when device loads, this script is executed. Typically you do not edit this script. +- `main.py` - this script executes right after `boot.py`. You can consider this your classic Arduino sketch, that runs as soon your board is powered. If you want a specific program to run on your board, save it to `main.py`. + +### Adding Modules + +It is possible to add modules, drivers or scripts directly to your board. It is also as simple as dragging and dropping it into the mass storage, and `import` it in your script. + +### Execute Scripts + +A really cool thing with this implementation is that you can pack the mass storage with many different scripts, and load them when needed. + +This can be done using only a simple line of code: + +```python +exec(open("script.py").read()) +``` + +This allows you to create a number of scripts and store it on the mass storage, and execute them from the board itself (e.g. a button). + +## Pin Map + +In the table below, you will find the matching between the **STM32H7** and **Arduino**. When writing MicroPython code, you need to use the pin designations listen in the STM32H7 column. + +| STM32H7 | Arduino | +| ------- | ------- | +| PB7 | D0 | +| PA9 | D1 | +| PA3 | D2 | +| PA2 | D3 | +| PJ8 | D4 | +| PA7 | D5 | +| PD13 | D6 | +| PB4 | D7 | +| PB8 | D8 | +| PB9 | D9 | +| PK1 | D10 | +| PJ10 | D11 | +| PJ11 | D12 | +| PH6 | D13 | +| PG14 | D14 | +| PC7 | D15 | +| PH13 | D16 | +| PI9 | D17 | +| PD5 | D18 | +| PD6 | D19 | +| PB11 | D20 | +| PH4 | D21 | +| PJ12 | D22 | +| PG13 | D23 | +| PG12 | D24 | +| PJ0 | D25 | +| PJ14 | D26 | +| PJ1 | D27 | +| PJ15 | D28 | +| PJ2 | D29 | +| PK3 | D30 | +| PJ3 | D31 | +| PK4 | D32 | +| PJ4 | D33 | +| PK5 | D34 | +| PJ5 | D35 | +| PK6 | D36 | +| PJ6 | D37 | +| PJ7 | D38 | +| PI14 | D39 | +| PE6 | D40 | +| PK7 | D41 | +| PI15 | D42 | +| PI10 | D43 | +| PG10 | D44 | +| PI13 | D45 | +| PH15 | D46 | +| PB2 | D47 | +| PK0 | D48 | +| PE4 | D49 | +| PI11 | D50 | +| PE5 | D51 | +| PK2 | D52 | +| PG7 | D53 | +| PI5 | D54 | +| PH8 | D55 | +| PA6 | D56 | +| PJ9 | D57 | +| PI7 | D58 | +| PI6 | D59 | +| PI4 | D60 | +| PH14 | D61 | +| PG11 | D62 | +| PH11 | D63 | +| PH10 | D64 | +| PH9 | D65 | +| PA1 | D66 | +| PD4 | D67 | +| PC6 | D68 | +| PI0 | D69 | +| PI1 | D70 | +| PI2 | D71 | +| PI3 | D72 | +| PC1 | D73 | +| PB12 | D74 | +| PD3 | D75 | +| PC4 | A0 | +| PC5 | A1 | +| PB0 | A2 | +| PB1 | A3 | +| PC3 | A4 | +| PC2 | A5 | +| PC0 | A6 | +| PA0 | A7 | +| PA4 | A12 | +| PA5 | A13 | + +## Conclusion + +In this article, we have learned how to install MicroPython on the GIGA R1, using the `dfu-util` tool. We have also gone through some useful tips and tricks that can help you develop and run MicroPython code on your board. + +For more information, visit the [MicroPython with Arduino documentation](/micropython). \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/hero-banner.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/hero-banner.png new file mode 100644 index 0000000000..5207d83ddb Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-micropython/hero-banner.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/giga-file-write.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/giga-file-write.png new file mode 100644 index 0000000000..bd22c1025c Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/giga-file-write.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/giga-keyboard-connect.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/giga-keyboard-connect.png new file mode 100644 index 0000000000..d9e0b9a11d Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/giga-keyboard-connect.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/usb-connectors.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/usb-connectors.png new file mode 100644 index 0000000000..c4f17d18ee Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/assets/usb-connectors.png differ diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/giga-usb.md b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/giga-usb.md new file mode 100644 index 0000000000..6d0169339c --- /dev/null +++ b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/giga-usb.md @@ -0,0 +1,542 @@ +--- +title: Guide to Arduino GIGA USB Features +description: 'Learn how you can turn your USB device into a mouse or keyboard, how to read & write to a USB mass storage, and connecting a keyboard via the USB-A connector.' +author: Karl Söderby +tags: [USB, USB HID, USBHost, Mass Storage, Keyboard, Mouse] +--- + +The GIGA R1 comes with a great range of supported USB features, including **USB HID, USB Host** and **Mass Storage**. It also comes with a USB-A connector that allow you to plug devices directly to your GIGA R1 board. + +It can easily be configured to act as a mouse or keyboard (HID device) or as a USB Host (connect a keyboard, USB stick). This makes it possible to create powerful interfaces, and build complex interactive projects. + +In this guide, we will take a look at the available features, how to enable them in a sketch and what circuit (if any) is required. + +## Hardware & Software Needed + +- [Arduino GIGA R1 WiFi](/hardware/giga-r1-wifi). +- USB Mass Storage Device (USB Stick). +- Keyboard. + +## USB Overview + +The GIGA R1 has two USB connectors: +- **USB-C** - for powering, programming & HID communication. +- **USB-A** - for USB-Host (connecting keyboards, USB sticks etc). + +![USB ports on GIGA R1.](assets/usb-connectors.png) + +***Note: do NOT connect the USB-A connector to your computer. This is not a programming port and if the `PA15` pin is enabled, it can damage your computer's USB port.*** + +Below is an example of how you should use the USB-C / USB-A connectors. + +![Keyboard connected to USB-A port.](assets/giga-keyboard-connect.png) + +## Enable/Disable USB-A Port + +To enable the USB-A port, you will need to define it as an output. You can also disable it inside of a sketch by writing a LOW state to it. + +```arduino +void setup(){ + pinMode(PA_15, OUTPUT); //enable the USB-A port +} + +void loop(){ + digitalWrite(PA_15, HIGH); //write a high state + digitalWrite(PA_15, LOW); //write a low state +} +``` + +***Please note that connecting devices to the USB-A that draw high amounts of current may cause the board to reset.*** + +## USB Mass Storage + +The USB-A connector onboard the GIGA R1 can be used to connect **USB mass storage devices**, for example, a USB stick. This can be used for a number of applications, including: +- Accessing large files such as images & audio files, +- Logging large amounts of data, +- Storing images or videos captured with a camera. + +USB mass storage devices connected needs to be formatted with the **FAT32** as a file system, using the **MBR partitioning scheme**. This is a requirement, and reading & writing will not work otherwise. + +### USB Designation + +To access the correct USB mass storage device, we need to specify the **designation** in the code. + +```arduino +mbed::FATFileSystem usb("USB_DRIVE_DESIGNATION") +``` + +This is so that our GIGA R1 can target the right USB device. + +Please note that when writing/reading to files, you will need to specify the correct path, for example: + +```arduino + +``` + +### List File Directory + +Below is an example sketch that can be used to **list** files in a USB mass storage device. + +```arduino +#include +#include +#include + +USBHostMSD msd; +mbed::FATFileSystem usb("usb"); + + +void setup() +{ + Serial.begin(115200); + + pinMode(PA_15, OUTPUT); //enable the USB-A port + digitalWrite(PA_15, HIGH); + + while (!Serial) + ; + + Serial.println("Starting USB Dir List example..."); + + // if you are using a Max Carrier uncomment the following line + // start_hub(); + + while (!msd.connect()) { + //while (!port.connected()) { + delay(1000); + } + + Serial.print("Mounting USB device... "); + int err = usb.mount(&msd); + if (err) { + Serial.print("Error mounting USB device "); + Serial.println(err); + while (1); + } + Serial.println("done."); + + char buf[256]; + + // Display the root directory + Serial.print("Opening the root directory... "); + DIR* d = opendir("/usb/"); + Serial.println(!d ? "Fail :(" : "Done"); + if (!d) { + snprintf(buf, sizeof(buf), "error: %s (%d)\r\n", strerror(errno), -errno); + Serial.print(buf); + } + Serial.println("done."); + + Serial.println("Root directory:"); + unsigned int count { 0 }; + while (true) { + struct dirent* e = readdir(d); + if (!e) { + break; + } + count++; + snprintf(buf, sizeof(buf), " %s\r\n", e->d_name); + Serial.print(buf); + } + Serial.print(count); + Serial.println(" files found!"); + + snprintf(buf, sizeof(buf), "Closing the root directory... "); + Serial.print(buf); + fflush(stdout); + err = closedir(d); + snprintf(buf, sizeof(buf), "%s\r\n", (err < 0 ? "Fail :(" : "OK")); + Serial.print(buf); + if (err < 0) { + snprintf(buf, sizeof(buf), "error: %s (%d)\r\n", strerror(errno), -errno); + Serial.print(buf); + } +} + +void loop() +{ +} +``` + +### File Read + +Below is an example sketch that can be used to **read** files from a USB mass storage device. + +```arduino +#include +#include +#include + +USBHostMSD msd; +mbed::FATFileSystem usb("usb"); + +// If you are using a Portenta Machine Control uncomment the following line +mbed::DigitalOut otg(PB_14, 0); + +void setup() { + Serial.begin(115200); + + pinMode(PA_15, OUTPUT); //enable the USB-A port + digitalWrite(PA_15, HIGH); + + while (!Serial); + + delay(2500); + Serial.println("Starting USB File Read example..."); + + // if you are using a Max Carrier uncomment the following line + //start_hub(); + + while (!msd.connect()) { + delay(1000); + } + + Serial.println("Mounting USB device..."); + int err = usb.mount(&msd); + if (err) { + Serial.print("Error mounting USB device "); + Serial.println(err); + while (1); + } + Serial.print("read done "); + mbed::fs_file_t file; + struct dirent *ent; + int dirIndex = 0; + int res = 0; + Serial.println("Open file.."); + FILE *f = fopen("/usb/Arduino.txt", "r+"); + char buf[256]; + Serial.println("File content:"); + + while (fgets(buf, 256, f) != NULL) { + Serial.print(buf); + } + + Serial.println("File closing"); + fflush(stdout); + err = fclose(f); + if (err < 0) { + Serial.print("fclose error:"); + Serial.print(strerror(errno)); + Serial.print(" ("); + Serial.print(-errno); + Serial.print(")"); + } else { + Serial.println("File closed"); + } +} + +void loop() { + +} +``` + +### File Write + +Below is an example sketch that can be used to **write** files from a USB mass storage device. + +```arduino +#include +#include +#include + +USBHostMSD msd; +mbed::FATFileSystem usb("usb"); + +// mbed::DigitalOut pin5(PC_6, 0); +mbed::DigitalOut otg(PB_8, 1); + +void setup() { + Serial.begin(115200); + + pinMode(PA_15, OUTPUT); //enable the USB-A port + digitalWrite(PA_15, HIGH); + + while (!Serial); + + msd.connect(); + + while (!msd.connected()) { + //while (!port.connected()) { + delay(1000); + } + + Serial.println("Mounting USB device..."); + int err = usb.mount(&msd); + if (err) { + Serial.print("Error mounting USB device "); + Serial.println(err); + while (1); + } + Serial.print("read done "); + mbed::fs_file_t file; + struct dirent *ent; + int dirIndex = 0; + int res = 0; + Serial.println("Open /usb/numbers.txt"); + FILE *f = fopen("/usb/numbers.txt", "w+"); + for (int i = 0; i < 10; i++) { + Serial.print("Writing numbers ("); + Serial.print(i); + Serial.println("/10)"); + fflush(stdout); + err = fprintf(f, "%d\n", i); + if (err < 0) { + Serial.println("Fail :("); + error("error: %s (%d)\n", strerror(errno), -errno); + } + } + + Serial.println("File closing"); + fflush(stdout); + err = fclose(f); + if (err < 0) { + Serial.print("fclose error:"); + Serial.print(strerror(errno)); + Serial.print(" ("); + Serial.print(-errno); + Serial.print(")"); + } else { + Serial.println("File closed"); + } +} + +void loop() { + +} +``` + +### Datalogger Example + +In the example below, we are reading logging the `A0` pin, where we are defining two parameters: +- `interval` - how long between each reading. +- `number_of_readings` - how many readings we should take. + +This is useful if you e.g. want to log a specific amount of samples for a specific amount of time. + +```arduino +#include +#include +#include + +USBHostMSD msd; +mbed::FATFileSystem usb("usb"); + +int err; +int count; +int number_of_readings = 100; //how many readings you want to take +int interval = 10; //how long between readings (milliseconds) + +void setup() { + Serial.begin(115200); + + pinMode(PA_15, OUTPUT); //enable the USB-A port + digitalWrite(PA_15, HIGH); + + while (!Serial); //stop program from executing until serial port opens + + msd.connect(); + + while (!msd.connected()) { + Serial.print("MSD not found."); + delay(1000); + } + + Serial.println("Mounting USB device..."); + + err = usb.mount(&msd); + if (err) { + Serial.print("Error mounting USB device "); + Serial.println(err); + while (1) + ; + } + Serial.print("read done "); + + //function to write to file + WriteToFile(); +} + +void loop() { +} + +void WriteToFile() { + mbed::fs_file_t file; + struct dirent *ent; + int dirIndex = 0; + int res = 0; + + Serial.println("Opening file.."); + FILE *f = fopen("/usb/log.txt", "w+"); + + for (int i = 0; i < number_of_readings; i++) { + count += 1; + + Serial.print("Reading Nr: "); + Serial.print(count); + Serial.print(", Value: "); + Serial.println(analogRead(A0)); + + fflush(stdout); + + int reading = analogRead(A0); + + err = fprintf(f, "%s", "Reading Nr: "); + err = fprintf(f, "%d", count); + err = fprintf(f, "%s", ", Value: "); + err = fprintf(f, "%d\n", reading); + + if (err < 0) { + Serial.println("Fail :("); + error("error: %s (%d)\n", strerror(errno), -errno); + } + delay(interval); + } + + Serial.println("File closing"); + fflush(stdout); + err = fclose(f); + + if (err < 0) { + Serial.print("fclose error:"); + Serial.print(strerror(errno)); + Serial.print(" ("); + Serial.print(-errno); + Serial.print(")"); + } else { + Serial.println("File closed"); + } +} +``` + +After logging data, remove the USB stick from your board, and insert it in your computer to see the data logged: + +![Data logged in .txt file.](assets/giga-file-write.png) + +## USB Host Keyboard + +It is possible to connect generic USB keyboards to the GIGA R1's USB-A connector without any additional circuitry. This library is included in the core, so it does not require any additional installation. + +```arduino +#include "HIDHost.h" + +Keyboard keyb; //create object + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial); + pinMode(PA_15, OUTPUT); //enable the USB-A port //enable the USB-A connector + keyb.begin(); //init the library +} + + +void loop() { + if (keyb.available()) { + Serial.println(keyb.read()); //print any incoming character + } +} +``` + +***Please note that he `PA15` pin must be configured as an `OUTPUT`.*** + +## USB HID + +It is possible to turn your GIGA R1 board into a Human Interface Device **(HID)**, aka mouse & keyboard, using the [USBHID](https://github.com/arduino/ArduinoCore-mbed/tree/master/libraries/USBHID) library which is included in the GIGA core. + +Among other things, you can: +- Create a custom keyboard, or a keyboard accessory, +- Create sophisticated game controllers, +- Accessories for VR/AR applications. + +### Keyboard + +***Important! When using the GIGA as a keyboard, make sure to include some sort of delay. Otherwise, you may end up printing things very fast, which can be an annoyance. If this happens nonetheless, double tap the reset button and upload a blank sketch to reset the board.*** + +To emulate a keyboard, we need to include `PluggableUSBHID.h` and `USBKeyboard.h`, and create an object using the `USBkeyboard` constructor. + +```arduino +#include "PluggableUSBHID.h" +#include "USBKeyboard.h" + +USBKeyboard Keyboard; +``` + +To send a single character, we can use the `putc()` method. + +```arduino +Keyboard.putc(97); //prints the letter 'a' +``` + +See the `DEC` column at [ascii-code.com](https://www.ascii-code.com/) to understand what number you need to print a specific character. + +To print a whole string, use the `printf()` method. + +```arduino +Keyboard.printf("Hello World!"); +``` + +To use modifiers and function keys, use the `key_code()` method. + +``` +Keyboard.key_code(KEY_F1); +``` + +To use media keys, use the `media_control()` method. + +``` +Keyboard.media_control(KEY_NEXT_TRACK); +``` + +***All modifiers, function and media control keys can be found in [this header file](https://github.com/arduino/ArduinoCore-mbed/blob/master/libraries/USBHID/src/USBKeyboard.h).*** + +### Mouse + +To emulate a mouse, we need to include `PluggableUSBHID.h` and `USBMouse.h`, and create an object using the `USBMouse` constructor. + +```arduino +#include "PluggableUSBHID.h" +#include "USBMouse.h" + +USBMouse Mouse; +``` + +To move the cursor, we can write the **x** and **y** coordinates directly, using the `move()` method. + +```arduino +Mouse.move(100,100); +``` + +For clicking the mouse, use the `click()` method. + +```arduino +Mouse.click(MOUSE_LEFT); +Mouse.click(MOUSE_RIGHT); +Mouse.click(MOUSE_MIDDLE); +``` + +For double clicking the mouse, use the `double_click()` method. + +``` +Mouse.double_click(MOUSE_LEFT); +``` + +To press and release the buttons on the mouse, we can use the `press()` and `release()` methods. This way, we can define how long we want the button to be pressed for. + +```arduino +Mouse.press(MOUSE_LEFT); +Mouse.press(MOUSE_RIGHT); +Mouse.press(MOUSE_MIDDLE); + +delay(1000); + +Mouse.release(); +``` + +## Summary + +The goal with this guide was to provide a summary of all the GIGA R1's features, including: +- Enabling and disabling the USB-A port. +- Read & Write to a USB mass storage device (MSD). +- Connecting keyboards and reading key presses. +- Emulate a mouse/keyboard through the HID interface. \ No newline at end of file diff --git a/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/hero-banner.png b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/hero-banner.png new file mode 100644 index 0000000000..b26b1754fd Binary files /dev/null and b/content/hardware/09.mega/boards/giga-r1-wifi/tutorials/giga-usb/hero-banner.png differ diff --git a/content/hardware/09.mega/family.md b/content/hardware/09.mega/family.md new file mode 100644 index 0000000000..e7e8573870 --- /dev/null +++ b/content/hardware/09.mega/family.md @@ -0,0 +1,4 @@ +--- +title: Mega +description: The largest Arduino form factor with a lot of GPIOs. +--- \ No newline at end of file diff --git a/content/hardware/09.mega/image-480.png b/content/hardware/09.mega/image-480.png new file mode 100644 index 0000000000..048369051d Binary files /dev/null and b/content/hardware/09.mega/image-480.png differ diff --git a/content/hardware/09.mega/image.png b/content/hardware/09.mega/image.png new file mode 100644 index 0000000000..048369051d Binary files /dev/null and b/content/hardware/09.mega/image.png differ diff --git a/static/resources/datasheets/stm32h747xi.pdf b/static/resources/datasheets/stm32h747xi.pdf new file mode 100644 index 0000000000..5b939f632d Binary files /dev/null and b/static/resources/datasheets/stm32h747xi.pdf differ diff --git a/static/resources/firmware/GIGAR1_MP_FW.dfu b/static/resources/firmware/GIGAR1_MP_FW.dfu new file mode 100644 index 0000000000..ec8612e8f9 Binary files /dev/null and b/static/resources/firmware/GIGAR1_MP_FW.dfu differ diff --git a/static/resources/misc/giga_audio_examples.zip b/static/resources/misc/giga_audio_examples.zip new file mode 100644 index 0000000000..994d03c61c Binary files /dev/null and b/static/resources/misc/giga_audio_examples.zip differ