Dirk (Diskussion | Beiträge) K (→Demo 1) |
Dirk (Diskussion | Beiträge) K (→Demo 2) |
||
Zeile 865: | Zeile 865: | ||
Datei RP6Control_ArduIO_02.c: | Datei RP6Control_ArduIO_02.c: | ||
− | <pre></pre> | + | <pre>/* |
+ | * **************************************************************************** | ||
+ | * RP6 ROBOT SYSTEM - RP6 CONTROL M32 Examples | ||
+ | * **************************************************************************** | ||
+ | * Example: RP6Control ArduIO | ||
+ | * Author(s): Dirk | ||
+ | * **************************************************************************** | ||
+ | * Description: | ||
+ | * In this example we show a second test for the ArduIO Board. | ||
+ | * | ||
+ | * ############################################################################ | ||
+ | * The Robot does NOT move in this example! You can simply put it on a table | ||
+ | * next to your PC and you should connect it to the PC via the USB Interface! | ||
+ | * ############################################################################ | ||
+ | * **************************************************************************** | ||
+ | */ | ||
+ | |||
+ | /*****************************************************************************/ | ||
+ | // Includes: | ||
+ | |||
+ | #include "RP6ControlLib.h" // The RP6 Control Library. | ||
+ | // Always needs to be included! | ||
+ | #include "RP6I2CmasterTWI.h" // Include the I2C-Bus Master Library | ||
+ | |||
+ | /*****************************************************************************/ | ||
+ | /*****************************************************************************/ | ||
+ | // Include our new "RP6_ArduIO library": | ||
+ | // (This is the library for accessing the ArduIO Board!) | ||
+ | |||
+ | #include "RP6_ArduIOLib.h" | ||
+ | |||
+ | /*****************************************************************************/ | ||
+ | // I2C Error handler | ||
+ | |||
+ | /** | ||
+ | * This function gets called automatically if there was an I2C Error like | ||
+ | * the slave sent a "not acknowledge" (NACK, error codes e.g. 0x20 or 0x30). | ||
+ | * The most common mistakes are: | ||
+ | * - using the wrong address for the slave | ||
+ | * - slave not active or not connected to the I2C-Bus | ||
+ | * - too fast requests for a slower slave | ||
+ | * Be sure to check this if you get I2C errors! | ||
+ | */ | ||
+ | void I2C_transmissionError(uint8_t errorState) | ||
+ | { | ||
+ | writeString_P("\nI2C ERROR --> TWI STATE IS: 0x"); | ||
+ | writeInteger(errorState, HEX); | ||
+ | writeChar('\n'); | ||
+ | } | ||
+ | |||
+ | /*****************************************************************************/ | ||
+ | // Main function - The program starts here: | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | initRP6Control(); // Always call this first! The Processor will not | ||
+ | // work correctly otherwise. | ||
+ | |||
+ | initLCD(); // Initialize the LC-Display (LCD) | ||
+ | // Always call this before using the LCD! | ||
+ | |||
+ | setLEDs(0b1111); | ||
+ | mSleep(500); | ||
+ | setLEDs(0b0000); | ||
+ | |||
+ | writeString_P("\n\nRP6Control ArduIO Test 2!\n"); | ||
+ | writeString_P("\nPLEASE ENSURE THAT NO PINS OF PLUG SV_H-BRIDGES ARE CONNECTED!!!\n"); | ||
+ | |||
+ | // IMPORTANT: | ||
+ | I2CTWI_initMaster(100); // Initialize the TWI Module for Master operation | ||
+ | // with 100kHz SCL Frequency | ||
+ | |||
+ | |||
+ | // Register the event handler: | ||
+ | I2CTWI_setTransmissionErrorHandler(I2C_transmissionError); | ||
+ | |||
+ | setLEDs(0b1111); | ||
+ | |||
+ | // Write a text message to the LCD: | ||
+ | showScreenLCD("################", "################"); | ||
+ | mSleep(1500); | ||
+ | showScreenLCD(" RP6Control M32", "Example Program"); | ||
+ | mSleep(2500); | ||
+ | showScreenLCD(" RP6 Ardu IO", " Selftest 2"); | ||
+ | mSleep(2500); | ||
+ | clearLCD(); | ||
+ | |||
+ | setLEDs(0b0000); | ||
+ | |||
+ | // --------------------------------------- | ||
+ | |||
+ | uint8_t duty_pct = 0; | ||
+ | |||
+ | startStopwatch1(); | ||
+ | |||
+ | // IMPORTANT: | ||
+ | arduio_init(); // ArduIO init!!! | ||
+ | |||
+ | writeString_P("\n===> PRESS BUTTON 5 TO STOP THE DEMO!!! <===\n\n"); | ||
+ | |||
+ | while(true) | ||
+ | { | ||
+ | if(getStopwatch1() > 1000) // 1s | ||
+ | { | ||
+ | // PWM controller test: | ||
+ | // LEDs & free PWMs & power PWMs dim UP: | ||
+ | writeString("==> DIM Tests: "); | ||
+ | writeInteger(duty_pct, DEC); | ||
+ | writeString(" % Duty Cycle\n"); | ||
+ | dimArduIOLED(1, DUTY_PCT(duty_pct)); | ||
+ | dimArduIOLED(2, DUTY_PCT(duty_pct)); | ||
+ | dimArduIOLED3(DUTY_PCT(duty_pct)); | ||
+ | dimArduIOLED4(DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPWM(1, DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPWM(2, DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPWM3(DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPWM4(DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPowerPWM(1, DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPowerPWM(2, DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPowerPWM3(DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPowerPWM4(DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPowerPWM(5, DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPowerPWM(6, DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPowerPWM7(DUTY_PCT(duty_pct)); | ||
+ | dimArduIOPowerPWM8(DUTY_PCT(duty_pct)); | ||
+ | duty_pct += 10; | ||
+ | if (duty_pct > 100) { | ||
+ | duty_pct = 0; | ||
+ | writeString("\n"); | ||
+ | } | ||
+ | |||
+ | // ArduIO shutdown: | ||
+ | uint8_t key = getPressedKeyNumber(); | ||
+ | if (key == 5) { | ||
+ | writeString("\nPress button 1 for ArduIO SHUTDOWN"); | ||
+ | writeString("\nor button 2, 3 or 4 to continue!!!\n"); | ||
+ | do { | ||
+ | mSleep(10); | ||
+ | key = getPressedKeyNumber(); | ||
+ | } while ((!key) || (key == 5)); | ||
+ | if (key == 1) { | ||
+ | writeString("\nPlease wait for ArduIO SHUTDOWN...\n"); | ||
+ | arduio_shutdown(); | ||
+ | mSleep(3000); | ||
+ | writeString("\nThe ArduIO now is in SHUTDOWN MODE!!!\n"); | ||
+ | mSleep(1000); | ||
+ | writeString("\nRESET the microcontroller now...\n\n"); | ||
+ | while(true) {}; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | setStopwatch1(0); | ||
+ | } | ||
+ | |||
+ | task_I2CTWI(); | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </pre> | ||
======Erklärung====== | ======Erklärung====== |
Version vom 23. November 2014, 11:51 Uhr
Inhaltsverzeichnis
RP6 ArduIO Erweiterungsmodul
Die RP6-ArduIO Erweiterungsplatine (siehe auch das Vorgängerprojekt,die RP6-MultiIO-Erweiterungsplatine) im üblichen RP6-Layout ist als reine I2C-Erweiterung sowohl für den RP6, als auch für Arduino-Boards und –Shields gedacht. Entwickelt wurde sie zusammen mit einigen Mitgliedern des Roboternetzes von fabqu (Hardwarearbeiten) und Dirk (Softwarearbeiten).
Umfangreiche Dokumentation, sämtliche Beispielprogramme und Bibliotheken, Daten, Teilelisten und eine Lötanleitung finden sich unten in den Weblinks.
Hardware
Der Hardware-Artikel befindet sich HIER.
Software
Hier geht es um die Software für das von fabqu designte ArduIO Board. Für dieses Board soll es eine gemeinsame Library für die drei wesentlichen Plattformen des RP6-Systems und eine Library für den Arduino UNO geben.
RP6 M256 WIFI, CONTROL M32, BASE
Für die RP6 M256 WiFi, RP6 CONTROL M32 und RP6(v2) Base gibt es hier eine gemeinsame ArduIO Library. Die nachfolgenden Demos zu den einzelnen RP6-Mikrocontroller-Systemen nutzen diese Library.
ArduIO Library
Hier findet ihr die neue AVR-GCC Library für das ArduIO Board. Sie ausgelegt für die RP6 M256 WiFi, die RP6 CONTROL M32 und die RP6(v2) Base. Für die RP6 CCPRO M128 wird es vielleicht eine eigene Library geben.
Die Library für das Ardu IO Projekt Board (= "ArduIO") geht von folgenden Voraussetzungen aus:
- Der RP6(v2) Roboter (= "BASE"), die RP6 CONTROL M32 (= "M32") oder RP6v2 M256 WiFi Platine (= "M256") wird für die Ansteuerung der ArduIO benutzt.
- Die BASE, M32 oder M256 ist der I2C-Bus Master.
- Die I2C-Bus Geschwindigkeit beträgt 100 kHz.
- Alle Hardware-Komponenten der ArduIO sind aufgebaut (1).
- Alle Jumper auf der ArduIO sind in ihrer Standardstellung (2).
- Die ArduIO ist mit dem XBUS der BASE, M32 oder M256 1:1 verbunden.
Zu (1): Wenn nicht alle Komponenten aufgebaut sind, sind die zugehörigen Funktionen natürlich nicht funktionsfähig und können nicht benutzt werden. Zu (2): Siehe folgende Abbildung!
Standard-Jumperstellung
Hinweis: Die Jumper sind orange eingezeichnet!
Die Jumper der Stromversorgung (JP_5V, JP_UB, JP_LOAD) wurden nicht berücksichtigt!
Die Library (Software-Bibliothek) besteht aus drei Teilen:
- Dem Configuration Header -> Hier stehen alle Definitionen und Festlegungen, die der grundlegenden Konfiguration der ArduIO dienen. Diese Datei kann auf die eigenen Hardware-Voraussetzungen angepaßt werden, ohne dass die eigentliche Library (Header und Source) verändert werden muss.
- Dem Library Header -> Hier gibt es Definitionen, Variablen- und Funktionsdeklarationen für die Library.
- Der Library Source -> Das ist die eigentliche Library.
Configuration Header
Diese Datei ist der "Configuration Header" der neuen ArduIO Library. Sie gehört in den Ordner /.../RP6Lib/RP6common/.
Datei RP6_ArduIO.h:
/* **************************************************************************** * _______________________ * \| RP6 ROBOT SYSTEM |/ * \_-_-_-_-_-_-_-_-_-_/ >>> COMMON * ---------------------------------------------------------------------------- * ----------------------------- [c]2014 - Dirk ------------------------------- * **************************************************************************** * File: RP6_ArduIO.h * Version: 1.0 * Target: RP6 Base & Processor Expansion - ATMEGA32 @8.00 or 16.00MHz * & RP6 M256 WiFi - ATMEGA2560 @16.00MHz * Author(s): Dirk * **************************************************************************** * Description: * Configuration header file for new ArduIO Board library. * * **************************************************************************** * THE CHANGELOG CAN BE FOUND AT THE END OF THIS FILE! * **************************************************************************** */ #ifndef RP6_ARDUIO_H #define RP6_ARDUIO_H /*****************************************************************************/ // ArduIO hardwired components: // - I2C PWM Controller (IC3: PCA9685) // - I2C I/O Expander 1 5V (IC8: PCA9535) // - I2C I/O Expander 2 5V (IC13: PCA9535) // - I2C I/O Expander 3 3V3 (IC12: PCA9535) // - I2C A/D and D/A Converter 1 (IC11: PCF8591) // - I2C A/D and D/A Converter 2 (IC10: PCF8591) // - I2C A/D and D/A Converter 3 (IC9: PCF8591) // - UB Voltage Sensor // - LEDs // - PWM Ports // - Power PWM Ports & H-Bridges /*****************************************************************************/ // Includes: #include "RP6_ArduIOConfig.h" // Configure the target system /*****************************************************************************/ // I2C PWM Controller (PCA9685): // (A5, A4, A3 always 0, A1 always 1!) #define I2C_ARDUIO_PWM_ADR 0x84 // A2/0 = 0/0 //#define I2C_ARDUIO_PWM_ADR 0x86 // A2/0 = 0/1 //#define I2C_ARDUIO_PWM_ADR 0x8c // A2/0 = 1/0 //#define I2C_ARDUIO_PWM_ADR 0x8e // A2/0 = 1/1 //#define I2C_ARDUIO_PWM_ADR 0xe0 // ALLCALLADR // --------------------------------------------------------------- #define PWM_FREQUENCY 1000 // 1kHz (default) // --------------------------------------------------------------- #define CHALL_LED 0 // All LEDs (channels) /*****************************************************************************/ // I2C I/O Expander (PCA9535): // (A1 always 1!) #define I2C_ARDUIO_IO_1_ADR 0x44 // A2/0 = 0/0 //#define I2C_ARDUIO_IO_1_ADR 0x46 // A2/0 = 0/1 //#define I2C_ARDUIO_IO_1_ADR 0x4c // A2/0 = 1/0 //#define I2C_ARDUIO_IO_1_ADR 0x4e // A2/0 = 1/1 //#define I2C_ARDUIO_IO_2_ADR 0x44 // A2/0 = 0/0 #define I2C_ARDUIO_IO_2_ADR 0x46 // A2/0 = 0/1 //#define I2C_ARDUIO_IO_2_ADR 0x4c // A2/0 = 1/0 //#define I2C_ARDUIO_IO_2_ADR 0x4e // A2/0 = 1/1 //#define I2C_ARDUIO_IO_3_ADR 0x44 // A2/0 = 0/0 //#define I2C_ARDUIO_IO_3_ADR 0x46 // A2/0 = 0/1 #define I2C_ARDUIO_IO_3_ADR 0x4c // A2/0 = 1/0 //#define I2C_ARDUIO_IO_3_ADR 0x4e // A2/0 = 1/1 /*****************************************************************************/ // I2C A/D and D/A Converter (PCF8591): // (A1 always 1!) #define I2C_ARDUIO_AD_1_ADR 0x94 // A2/0 = 0/0 //#define I2C_ARDUIO_AD_1_ADR 0x96 // A2/0 = 0/1 //#define I2C_ARDUIO_AD_1_ADR 0x9c // A2/0 = 1/0 //#define I2C_ARDUIO_AD_1_ADR 0x9e // A2/0 = 1/1 //#define I2C_ARDUIO_AD_2_ADR 0x94 // A2/0 = 0/0 #define I2C_ARDUIO_AD_2_ADR 0x96 // A2/0 = 0/1 //#define I2C_ARDUIO_AD_2_ADR 0x9c // A2/0 = 1/0 //#define I2C_ARDUIO_AD_2_ADR 0x9e // A2/0 = 1/1 //#define I2C_ARDUIO_AD_3_ADR 0x94 // A2/0 = 0/0 //#define I2C_ARDUIO_AD_3_ADR 0x96 // A2/0 = 0/1 #define I2C_ARDUIO_AD_3_ADR 0x9c // A2/0 = 1/0 //#define I2C_ARDUIO_AD_3_ADR 0x9e // A2/0 = 1/1 /*****************************************************************************/ // UB Voltage Sensor: // (Connected to A/D and D/A Converter 1 (ADDA_1: IC11), AIN3 (AD13), // if jumper JP_AD-UB on the ArduIO Board is CLOSED!) #define ADCVAL_UB_LOW 175 // UB 6.9V /*****************************************************************************/ // LEDs: // (Status LED1..LED4 are connected to LED11..LED8 of the PCA9685!) #define CHLED1 12 #define CHLED2 11 #define CHLED3 10 #define CHLED4 9 /*****************************************************************************/ // PWM Ports: // (Ports PWM1..PWM4 are connected to LED15..LED12 of the PCA9685!) #define CHPWM1 16 #define CHPWM2 15 #define CHPWM3 14 #define CHPWM4 13 /*****************************************************************************/ // Power PWM Ports & H-Bridges: // (H-Bridges HB1/HB2 are connected to LED0..LED3/LED4..LED7 of the PCA9685!) // Power PWM Ports: #define CHPOWERPWM1_P 1 #define CHPOWERPWM2_N 2 #define CHPOWERPWM3_P 3 #define CHPOWERPWM4_N 4 #define CHPOWERPWM5_P 5 #define CHPOWERPWM6_N 6 #define CHPOWERPWM7_P 7 #define CHPOWERPWM8_N 8 // H-Bridges: #define CHHB1_P1 1 #define CHHB1_N1 2 #define CHHB1_P2 3 #define CHHB1_N2 4 #define CHHB2_P1 5 #define CHHB2_N1 6 #define CHHB2_P2 7 #define CHHB2_N2 8 /*****************************************************************************/ // Interrupt portpin definitions: // Select INTx portpin definitions depending on RP6_ArduIOConfig.h: #ifdef ARDUIO_RP6BASE // Interrupt I/O portpin definitions (RP6Base): #define IO_ARDUIO_INT1_IN E_INT1 // ADC4 PA4 XBUS Pin 8 #define IO_ARDUIO_INT1_DDR DDRA #define IO_ARDUIO_INT1_PIN PINA #define IO_ARDUIO_INT1_PORT PORTA #else #ifdef ARDUIO_RP6CONTROL // Interrupt I/O portpin definitions (RP6Control M32): #define IO_ARDUIO_INT1_IN EINT1 // INT0 PD2 XBUS Pin 8 #define IO_ARDUIO_INT1_DDR DDRD #define IO_ARDUIO_INT1_PIN PIND #define IO_ARDUIO_INT1_PORT PORTD #define IO_ARDUIO_INT2_IN EINT2 // INT1 PD3 XBUS Pin 11 #define IO_ARDUIO_INT2_DDR DDRD #define IO_ARDUIO_INT2_PIN PIND #define IO_ARDUIO_INT2_PORT PORTD #define IO_ARDUIO_INT3_IN EINT3 // AIN0/INT2 PB2 XBUS Pin 9 #define IO_ARDUIO_INT3_DDR DDRB #define IO_ARDUIO_INT3_PIN PINB #define IO_ARDUIO_INT3_PORT PORTB #else #ifdef ARDUIO_RP6M256WIFI // Interrupt I/O portpin definitions (RP6M256 WiFi): #define IO_ARDUIO_INT1_IN INT1_PI12 // PCINT12 PJ3 XBUS Pin 8 #define IO_ARDUIO_INT1_DDR DDRJ #define IO_ARDUIO_INT1_PIN PINJ #define IO_ARDUIO_INT1_PORT PORTJ #define IO_ARDUIO_INT2_IN INT2_PI15 // PCINT15 PJ6 XBUS Pin 11 #define IO_ARDUIO_INT2_DDR DDRJ #define IO_ARDUIO_INT2_PIN PINJ #define IO_ARDUIO_INT2_PORT PORTJ #define IO_ARDUIO_INT3_IN INT3_PI14 // PCINT14 PJ5 XBUS Pin 9 #define IO_ARDUIO_INT3_DDR DDRJ #define IO_ARDUIO_INT3_PIN PINJ #define IO_ARDUIO_INT3_PORT PORTJ #define IO_ARDUIO_INTU_IN INTU_PI13 // PCINT13 PJ4 XBUS Pin 7 #define IO_ARDUIO_INTU_DDR DDRJ #define IO_ARDUIO_INTU_PIN PINJ #define IO_ARDUIO_INTU_PORT PORTJ #else #error DEFINE "ARDUIO_RP6BASE", "ARDUIO_RP6CONTROL" OR "ARDUIO_RP6M256WIFI" #error AS TARGET IN RP6_ArduIOConfig.h #endif #endif #endif /*****************************************************************************/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* Arduino Uno Expander definitions */ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ // ATTENTION: Using this library you MAY NOT connect an Arduino Uno Board to // the RP6 ArduIO Board using the Arduino Uno Expander pin headers // on the ArduIO Board, if the Arduino Uno Board is the I2C bus // master!!!!!! // BE VERY CAREFUL: // You may damage the Arduino Uno AND your RP6 ArduIO Board! // // Of course you may connect Arduino ADDON boards (shields) to the // Arduino Uno Expander pin headers on the ArduIO Board. // BE VERY CAREFUL: // Not all Arduino shields will work on the RP6 ArduIO Board! // You may damage the Arduino shield AND your RP6 ArduIO Board! /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ // Arduino Uno Expander <-> RP6_ArduIO Mapping Table: // Arduino Uno: ATmega328: RP6_ArduIO: // Pin Function Pin Functions Pin Name IO ADDA // ----------------------------------------------------------- // 0 D0 RX PD0 RXD_PCINT16 P00 GP200 2 // 1 D1 TX PD1 TXD_PCINT17 P01 GP201 2 // 2 D2 PD2 INT0_PCINT18 P02 GP202 2 // 3 D3 PWM PD3 INT1_OC2B_PCINT19 P03 GP203 2 // 4 D4 PD4 T0_XCK_PCINT20 P04 GP204 2 // 5 D5 PWM PD5 T1_OC0B_PCINT21 P05 GP205 2 // 6 D6 PWM PD6 AIN0_OC0A_PCINT22 P06 GP206 2 // 7 D7 PD7 AIN1_PCINT23 P07 GP207 2 // 8 D8 PB0 ICP1_CLKO_PCINT0 P15 GP215 2 // 9 D9 PWM PB1 OC1A_PCINT1 P14 GP214 2 // 10 D10 PWM PB2 SS_OC1B_PCINT2 P13 GP213 2 // 11 D11 PWM PB3 MOSI_OC2A_PCINT13 P12 GP212 2 // 12 D12 PB4 MISO_PCINT4 P11 GP211 2 // 13 D13 PB5 SCK_PCINT5 P10 GP210 2 // // 0 A0 PC0 ADC0_PCINT8 AIN0 AD30 3 // 1 A1 PC1 ADC1_PCINT9 AIN1 AD31 3 // 2 A2 PC2 ADC2_PCINT10 AIN2 AD32 3 // 3 A3 PC3 ADC3_PCINT11 AIN3 AD33 3 // 4 A4 SDA PC4 ADC4_SDA_PCINT12 SDA // 5 A5 SCL PC5 ADC5_SCL_PCINT13 SCL // Special "PWM portpin" connections: // Arduino Uno: ATmega328: RP6_ArduIO: // Pin Function Pin Functions Name JP_ Pins (*) // ------------------------------------------------------------ // 3 D3 PWM PD3 INT1_OC2B_PCINT19 PWM3 PWM3 2-3 // 5 D5 PWM PD5 T1_OC0B_PCINT21 PWM1 PWM1 1-2 // 6 D6 PWM PD6 AIN0_OC0A_PCINT22 PWM1 PWM1 2-3 // 9 D9 PWM PB1 OC1A_PCINT1 PWM2 PWM2 1-2 // 10 D10 PWM PB2 SS_OC1B_PCINT2 PWM2 PWM2 2-3 // 11 D11 PWM PB3 MOSI_OC2A_PCINT13 PWM3 PWM3 1-2 // (At (*): Pins of JP_PWMx to be closed!) // Arduino Uno Expander ATmega 328 portpin names: #define IO_ARD_D0_RXD_PCINT16 0 #define IO_ARD_D1_TXD_PCINT17 1 #define IO_ARD_D2_INT0_PCINT18 2 #define IO_ARD_D3_INT1_OC2B_PCINT19 3 #define IO_ARD_D4_T0_XCK_PCINT20 4 #define IO_ARD_D5_T1_OC0B_PCINT21 5 #define IO_ARD_D6_AIN0_OC0A_PCINT22 6 #define IO_ARD_D7_AIN1_PCINT23 7 #define IO_ARD_D8_ICP1_CLKO_PCINT0 8 #define IO_ARD_D9_OC1A_PCINT1 9 #define IO_ARD_D10_SS_OC1B_PCINT2 10 #define IO_ARD_D11_MOSI_OC2A_PCINT13 11 #define IO_ARD_D12_MISO_PCINT4 12 #define IO_ARD_D13_SCK_PCINT5 13 #define AD_ARD_A0_ADC0_PCINT8 0 #define AD_ARD_A1_ADC1_PCINT9 1 #define AD_ARD_A2_ADC2_PCINT10 2 #define AD_ARD_A3_ADC3_PCINT11 3 #define AD_ARD_A4_ADC4_SDA_PCINT12 4 #define AD_ARD_A5_ADC5_SCL_PCINT13 5 // Arduino Uno Expander portpin short definitions: #define IO_ARD_D0_RX 0 #define IO_ARD_D1_TX 1 #define IO_ARD_D2 2 #define IO_ARD_D3_PWM 3 #define IO_ARD_D4 4 #define IO_ARD_D5_PWM 5 #define IO_ARD_D6_PWM 6 #define IO_ARD_D7 7 #define IO_ARD_D8 8 #define IO_ARD_D9_PWM 9 #define IO_ARD_D10_PWM 10 #define IO_ARD_D11_PWM 11 #define IO_ARD_D12 12 #define IO_ARD_D13 13 #define AD_ARD_A0 0 #define AD_ARD_A1 1 #define AD_ARD_A2 2 #define AD_ARD_A3 3 #define AD_ARD_A4_SDA 4 #define AD_ARD_A5_SCL 5 // Arduino Uno Expander PWM portpin definitions: // (Use only ONE of the IO_ARD_PWMx definitions! Never two or three!) #define IO_ARD_PWM1 0 // JP_PWM1 open //#define IO_ARD_PWM1 IO_ARD_D5_PWM // JP_PWM1 1-2 closed //#define IO_ARD_PWM1 IO_ARD_D6_PWM // JP_PWM1 2-3 closed // IMPORTANT: If JP_PWM1 is CLOSED on any pins, the JP_ARD2 jumper of that // Arduino Uno Expander PWM portpin (D5 or D6) MUST BE OPEN!!! #define IO_ARD_PWM2 0 // JP_PWM2 open //#define IO_ARD_PWM2 IO_ARD_D9_PWM // JP_PWM2 1-2 closed //#define IO_ARD_PWM2 IO_ARD_D10_PWM // JP_PWM2 2-3 closed // IMPORTANT: If JP_PWM2 is CLOSED on any pins, the JP_ARD2 jumper of that // Arduino Uno Expander PWM portpin (D9 or D10) MUST BE OPEN!!! #define IO_ARD_PWM3 0 // JP_PWM3 open //#define IO_ARD_PWM3 IO_ARD_D11_PWM // JP_PWM3 1-2 closed //#define IO_ARD_PWM3 IO_ARD_D3_PWM // JP_PWM3 2-3 closed // IMPORTANT: If JP_PWM3 is CLOSED on any pins, the JP_ARD2 jumper of that // Arduino Uno Expander PWM portpin (D11 or D3) MUST BE OPEN!!! /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ // Arduino Uno Expander read/write software examples: // 1. Writing to the digital portpins (D0..D13): // io2outs.ARD_D10 = true; // updateArduino_Uno_Exp_IO(); // Set D10 // ==> Hint: If D10 is connected to PWM2, then D10 will be set by this // PWM port instead of IO_2: P13!!! // io2outs.ARD_D8 = false; // updateArduino_Uno_Exp_IO(); // Clear D8 // setArduino_Uno_Exp_IO(0b0001000000000000);// Set D9 & clear all others // ==> Bit positions in the io2ins and io2outs word: // 0b0000000000000000 // ||| || | // Arduino: ||D8 |D7 D0 // n.c. D13 // 2. Controlling the digital "PWM portpins" (D3, 5, 6, 9, 10, 11): // ==> If one of these pins is disconnected from the IO_2 portpins and // instead is connected to a PWM port (PWM1, 2, 3), this "PWM portpin" // can be controlled by the PWM function: // dimArduino_Uno_Exp_PWM(1,duty); // Set the D5 OR D6 duty cycle // dimArduino_Uno_Exp_PWM1(duty); // The same! // ==> Hint: Depending on JP_PWM1 the PWM can be found at D5 OR D6!!! // 3. Reading the digital portpins (D0..D13): // configArduIO_IO2(0b1111111111111111); // All portpins are INPUTs // ==> This function must be called only ONCE! // task_readArduino_Uno_Exp_IO(); // Read D0..D13 // io_D0 = io2ins.ARD_D0; // This is D0 // io_D11 = io2ins.ARD_D11; // This is D11 // all_ios = io2ins.word & 0x3fff; // All portpins in 1 word // 4. Reading the analog portpins (A0..A3): // task_readArduino_Uno_Exp_AD(); // Read A0..A3 // adc_A0 = ad3ins.ARD_A0; // This is A0 // adc_A3 = ad3ins.ARD_A3; // This is A3 // 5. Reading all portpins and the interrupt signal: // task_Arduino_Uno_Exp(); // Read D0..D13, A0..A3 and // // PCA9535 (2) INT // int = interrupt_RP6ArduIOstatus.ioexp_2 // This is PCA9535 (2) INT // ==> Hint 1: This XBUS INT1 indicates a level change on D0..D13!!! // ==> Hint 2: If the variable interrupt_rp6arduiostatus_changed becomes // TRUE after execution of this task, INT1 has changed!!! // ==> Hint 3: Pins 1-2 of jumper JP_INT3V3 must be CLOSED!!! /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* Arduino Uno Expander definitions end */ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*****************************************************************************/ #endif /****************************************************************************** * Additional info * **************************************************************************** * Changelog: * * ---> changes are documented in the file "RP6_ArduIOLib.c" * * **************************************************************************** */ /*****************************************************************************/ // EOF
Library Header
Diese Datei ist der "Header" der neuen ArduIO Library. Sie gehört in den Ordner /.../RP6Lib/RP6common/.
Datei RP6_ArduIOLib.h:
Library Source
Diese Datei enthält den "Sourcecode" der neuen ArduIO Library. Sie gehört in den Ordner /.../RP6Lib/RP6common/.
Datei RP6_ArduIOLib.c:
Erklärung
RP6 M256 WIFI
Die Demos für die RP6 M256 WiFi (und -wenn ihr wollt- auch eure eigenen Programme) nutzen die ArduIO Library, s.o.!
Config
Diese Datei enthält nur die Information, welches RP6-Mikrocontroller-System (RP6 Base, RP6 CONTROL M32, RP6 M256 WiFi) das ArduIO Board ansteuert. Sie gehört in den Projektordner.
Datei RP6_ArduIOConfig.h:
/** * Settings for the RP6_ArduIO Library */ #ifndef RP6_ARDUIOCONFIG_H #define RP6_ARDUIOCONFIG_H /** * Define the target here: * (Use only ONE of them! Never two or three!) */ //#define ARDUIO_RP6BASE //#define ARDUIO_RP6CONTROL #define ARDUIO_RP6M256WIFI #endif
makefile (z.B. für Demo 1):
... TARGET = RP6M256_ArduIO_01 ... SRC += $(RP6_LIB_PATH)/RP6common/RP6_ArduIOLib.c ...
Demos der M32 anpassen
Es ist einfach, die M32 Demos an die M256 anzupassen. Die ArduIO Library braucht nicht verändert zu werden.
Folgende Anpassungen müssen gemacht werden:
- #include "RP6ControlLib.h" ==> #include "RP6M256Lib.h" - initRP6Control(); ==> initRP6M256(); - getPressedKeyNumber() ==> Tastenabfrage komplett entfernen!
Zusätzlich können bei der M256 alle UART-Ausgaben auf WiFi umgeleitet werden. Dazu muß an die UART-Ausgabebefehle "_WIFI" angehängt werden.
Beispiel:
- writeString_P("Text"); ==> writeString_P_WIFI("Text");
Die Funktion writeDouble() der M32 Demos kann für die WiFi-Ausgabe ersetzt werden durch:
void writeDouble_WIFI(double number, uint8_t width, uint8_t prec) {char buffer[width + 1]; dtostrf(number, width, prec, &buffer[0]); writeString_WIFI(&buffer[0]); }
RP6 CONTROL M32
Diese Demos für die RP6 CONTROL M32 (und -wenn ihr wollt- auch eure eigenen Programme) nutzen die ArduIO Library, s.o.!
Config
Diese Datei enthält nur die Information, welches RP6-Mikrocontroller-System (RP6 Base, RP6 CONTROL M32, RP6 M256 WiFi) das ArduIO Board ansteuert. Sie gehört in den Projektordner.
Datei RP6_ArduIOConfig.h:
/** * Settings for the RP6_ArduIO Library */ #ifndef RP6_ARDUIOCONFIG_H #define RP6_ARDUIOCONFIG_H /** * Define the target here: * (Use only ONE of them! Never two or three!) */ //#define ARDUIO_RP6BASE #define ARDUIO_RP6CONTROL //#define ARDUIO_RP6M256WIFI #endif
makefile (z.B. für Demo 1):
... TARGET = RP6Control_ArduIO_01 ... SRC += $(RP6_LIB_PATH)/RP6common/RP6_ArduIOLib.c ...
Demo 1
Datei RP6Control_ArduIO_01.c:
/* * **************************************************************************** * RP6 ROBOT SYSTEM - RP6 CONTROL M32 Examples * **************************************************************************** * Example: RP6Control ArduIO * Author(s): Dirk * **************************************************************************** * Description: * In this example we show a first test for the ArduIO Board. * * ############################################################################ * The Robot does NOT move in this example! You can simply put it on a table * next to your PC and you should connect it to the PC via the USB Interface! * ############################################################################ * **************************************************************************** */ /*****************************************************************************/ // Includes: #include "RP6ControlLib.h" // The RP6 Control Library. // Always needs to be included! #include "RP6I2CmasterTWI.h" // Include the I2C-Bus Master Library /*****************************************************************************/ /*****************************************************************************/ // Include our new "RP6_ArduIO library": // (This is the library for accessing the ArduIO Board!) #include "RP6_ArduIOLib.h" /*****************************************************************************/ // Define the kind of demo: // (If you don't define WRITE_TEST the READ TEST will be performed!) #define WRITE_TEST /*****************************************************************************/ /** * Write a floating point number to the UART. * * Example: * * // Write a floating point number to the UART (no exponent): * writeDouble(1234567.890, 11, 3); * * The value of prec (precision) defines the number of decimal places. * For 32 bit floating point variables (float, double ...) 6 is * the max. value for prec (7 relevant digits). * The value of width defines the overall number of characters in the * floating point number including the decimal point. The number of * pre-decimal positions is: (width - prec - 1). */ void writeDouble(double number, uint8_t width, uint8_t prec) {char buffer[width + 1]; dtostrf(number, width, prec, &buffer[0]); writeString(&buffer[0]); } /*****************************************************************************/ // I2C Error handler /** * This function gets called automatically if there was an I2C Error like * the slave sent a "not acknowledge" (NACK, error codes e.g. 0x20 or 0x30). * The most common mistakes are: * - using the wrong address for the slave * - slave not active or not connected to the I2C-Bus * - too fast requests for a slower slave * Be sure to check this if you get I2C errors! */ void I2C_transmissionError(uint8_t errorState) { writeString_P("\nI2C ERROR --> TWI STATE IS: 0x"); writeInteger(errorState, HEX); writeChar('\n'); } /*****************************************************************************/ // Main function - The program starts here: int main(void) { initRP6Control(); // Always call this first! The Processor will not // work correctly otherwise. initLCD(); // Initialize the LC-Display (LCD) // Always call this before using the LCD! setLEDs(0b1111); mSleep(500); setLEDs(0b0000); writeString_P("\n\nRP6Control ArduIO Test 1!\n"); #ifdef WRITE_TEST writeString_P("\nPLEASE ENSURE THAT NO PINS OF PLUG SV_H-BRIDGES ARE CONNECTED!!!\n"); #endif writeString_P("\n"); // IMPORTANT: I2CTWI_initMaster(100); // Initialize the TWI Module for Master operation // with 100kHz SCL Frequency // Register the event handler: I2CTWI_setTransmissionErrorHandler(I2C_transmissionError); setLEDs(0b1111); // Write a text message to the LCD: showScreenLCD("################", "################"); mSleep(1500); showScreenLCD(" RP6Control M32", "Example Program"); mSleep(2500); showScreenLCD(" RP6 Ardu IO", " Selftest 1"); mSleep(2500); clearLCD(); setLEDs(0b0000); // --------------------------------------- uint8_t onoff = 0; startStopwatch1(); // IMPORTANT: arduio_init(); // ArduIO init!!! #ifdef WRITE_TEST writeString_P("Test -> LED1\n"); setArduIOLED1(1); mSleep(500); setArduIOLED1(0); mSleep(500); setArduIOLED1(1); mSleep(1000); writeString_P("Test -> LED2\n"); setArduIOLED2(1); mSleep(500); setArduIOLED2(0); mSleep(500); setArduIOLED2(1); mSleep(1000); writeString_P("Test -> LED3\n"); setArduIOLED3(1); mSleep(500); setArduIOLED3(0); mSleep(500); setArduIOLED3(1); mSleep(1000); writeString_P("Test -> LED4\n"); setArduIOLED4(1); mSleep(500); setArduIOLED4(0); mSleep(500); setArduIOLED4(1); mSleep(500); setArduIOLEDs(0b0000); configArduIO_IO1(0); configArduIO_IO2(0); configArduIO_IO3(0); // All IOs OUTPUTs mSleep(100); #else configArduIO_IO1(0b1111111111111111); configArduIO_IO2(0b1111111111111111); configArduIO_IO3(0b1111111111111111); // All IOs INPUTs mSleep(100); #endif writeString_P("\n===> PRESS BUTTON 5 TO STOP THE DEMO!!! <===\n\n"); while(true) { if(getStopwatch1() > 1000) // 1s { if (onoff) onoff = 0; else onoff = 1; #ifndef WRITE_TEST // UB voltage sensor ADC test: ubv = measureUb(); writeString("\nUB Voltage: "); writeDouble(ubv, 4, 1); writeString("V\nADC UB: "); writeInteger(adcub, DEC); writeString("\n"); #else // PWM controller test: // LEDs & IOs & free PWMs & power PWMs ON/OFF: if (onoff) { setArduIO_IO1(0xffff); setArduIO_IO2(0xffff); setArduIO_IO3(0xffff); // All IOs high setArduIOLED1(1); setArduIOLED2(0); setArduIOLED3(0); setArduIOLED4(1); setArduIOPWM1(1); setArduIOPWM2(0); setArduIOPWM3(0); setArduIOPWM4(1); setArduIOPowerPWMs(0b10101010); } else { setArduIO_IO1(0); setArduIO_IO2(0); setArduIO_IO3(0); // All IOs low setArduIOLEDs(0b0110); setArduIOPWMs(0b0110); setArduIOPowerPWMs(0b01010101); } #endif #ifndef WRITE_TEST // I/O Expander 1 read test: task_readArduIO_IO1(); // Read GP100..GP117 writeString("\nIO_1: "); writeIntegerLength(io1ins.word, BIN, 16); writeString("\n"); // I/O Expander 2 read test: task_readArduIO_IO2(); // Read GP200..GP217 writeString("\nIO_2: "); writeIntegerLength(io2ins.word, BIN, 16); writeString("\n ARD: 1111"); writeString("\n 89012376543210\n"); // I/O Expander 3 read test: task_readArduIO_IO3(); // Read GP300..GP317 writeString("\nIO_3: "); writeIntegerLength(io3ins.word, BIN, 16); writeString("\n"); // AD/DA Converter 1 ADC test: task_readArduIO_AD1(); // Read AD10..AD13 writeString("ADDA_1: "); writeIntegerLength(ad1ins.AD10, DEC, 3); writeString(" | "); writeIntegerLength(ad1ins.AD11, DEC, 3); writeString(" | "); writeIntegerLength(ad1ins.AD12, DEC, 3); writeString(" | "); writeIntegerLength(ad1ins.AD13, DEC, 3); writeString("\n U[cV]: "); writeIntegerLength(UCV_AD(ad1ins.AD10), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad1ins.AD11), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad1ins.AD12), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad1ins.AD13), DEC, 3); writeString("\n A0 | A1 | A2 | A3\n"); // AD/DA Converter 2 ADC test: task_readArduIO_AD2(); // Read AD20..AD23 writeString("ADDA_2: "); writeIntegerLength(ad2ins.AD20, DEC, 3); writeString(" | "); writeIntegerLength(ad2ins.AD21, DEC, 3); writeString(" | "); writeIntegerLength(ad2ins.AD22, DEC, 3); writeString(" | "); writeIntegerLength(ad2ins.AD23, DEC, 3); writeString("\n U[cV]: "); writeIntegerLength(UCV_AD(ad2ins.AD20), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad2ins.AD21), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad2ins.AD22), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad2ins.AD23), DEC, 3); writeString("\n A0 | A1 | A2 | A3\n"); // AD/DA Converter 3 ADC test: task_readArduIO_AD3(); // Read AD30..AD33 writeString("ADDA_3: "); writeIntegerLength(ad3ins.ARD_A0, DEC, 3); writeString(" | "); writeIntegerLength(ad3ins.ARD_A1, DEC, 3); writeString(" | "); writeIntegerLength(ad3ins.ARD_A2, DEC, 3); writeString(" | "); writeIntegerLength(ad3ins.ARD_A3, DEC, 3); writeString("\n U[cV]: "); writeIntegerLength(UCV_AD(ad3ins.ARD_A0), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad3ins.ARD_A1), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad3ins.ARD_A2), DEC, 3); writeString(" | "); writeIntegerLength(UCV_AD(ad3ins.ARD_A3), DEC, 3); writeString("\n ARD: A0 | A1 | A2 | A3\n"); #else // AD/DA Converter 1..3 DAC test: if (onoff) { writeString("==> DA1..3: 1.50V\n"); writeArduIO_DA1(AOUT_CV(150)); // DA1: 1.5V writeArduIO_DA2(AOUT_CV(150)); // DA2: 1.5V writeArduIO_DA3(AOUT_CV(150)); // DA3: 1.5V } else { writeString("==> DA1..3: 3.50V\n"); writeArduIO_DA1(AOUT_CV(350)); // DA1: 3.5V writeArduIO_DA2(AOUT_CV(350)); // DA2: 3.5V writeArduIO_DA3(AOUT_CV(350)); // DA3: 3.5V } #endif // ArduIO shutdown: uint8_t key = getPressedKeyNumber(); if (key == 5) { writeString("\nPress button 1 for ArduIO SHUTDOWN"); writeString("\nor button 2, 3 or 4 to continue!!!\n"); do { mSleep(10); key = getPressedKeyNumber(); } while ((!key) || (key == 5)); if (key == 1) { writeString("\nPlease wait for ArduIO SHUTDOWN...\n"); arduio_shutdown(); mSleep(3000); writeString("\nThe ArduIO now is in SHUTDOWN MODE!!!\n"); mSleep(1000); writeString("\nRESET the microcontroller now...\n\n"); while(true) {}; } } setStopwatch1(0); } task_I2CTWI(); } return 0; }
Erklärung
Demo 2
Datei RP6Control_ArduIO_02.c:
/* * **************************************************************************** * RP6 ROBOT SYSTEM - RP6 CONTROL M32 Examples * **************************************************************************** * Example: RP6Control ArduIO * Author(s): Dirk * **************************************************************************** * Description: * In this example we show a second test for the ArduIO Board. * * ############################################################################ * The Robot does NOT move in this example! You can simply put it on a table * next to your PC and you should connect it to the PC via the USB Interface! * ############################################################################ * **************************************************************************** */ /*****************************************************************************/ // Includes: #include "RP6ControlLib.h" // The RP6 Control Library. // Always needs to be included! #include "RP6I2CmasterTWI.h" // Include the I2C-Bus Master Library /*****************************************************************************/ /*****************************************************************************/ // Include our new "RP6_ArduIO library": // (This is the library for accessing the ArduIO Board!) #include "RP6_ArduIOLib.h" /*****************************************************************************/ // I2C Error handler /** * This function gets called automatically if there was an I2C Error like * the slave sent a "not acknowledge" (NACK, error codes e.g. 0x20 or 0x30). * The most common mistakes are: * - using the wrong address for the slave * - slave not active or not connected to the I2C-Bus * - too fast requests for a slower slave * Be sure to check this if you get I2C errors! */ void I2C_transmissionError(uint8_t errorState) { writeString_P("\nI2C ERROR --> TWI STATE IS: 0x"); writeInteger(errorState, HEX); writeChar('\n'); } /*****************************************************************************/ // Main function - The program starts here: int main(void) { initRP6Control(); // Always call this first! The Processor will not // work correctly otherwise. initLCD(); // Initialize the LC-Display (LCD) // Always call this before using the LCD! setLEDs(0b1111); mSleep(500); setLEDs(0b0000); writeString_P("\n\nRP6Control ArduIO Test 2!\n"); writeString_P("\nPLEASE ENSURE THAT NO PINS OF PLUG SV_H-BRIDGES ARE CONNECTED!!!\n"); // IMPORTANT: I2CTWI_initMaster(100); // Initialize the TWI Module for Master operation // with 100kHz SCL Frequency // Register the event handler: I2CTWI_setTransmissionErrorHandler(I2C_transmissionError); setLEDs(0b1111); // Write a text message to the LCD: showScreenLCD("################", "################"); mSleep(1500); showScreenLCD(" RP6Control M32", "Example Program"); mSleep(2500); showScreenLCD(" RP6 Ardu IO", " Selftest 2"); mSleep(2500); clearLCD(); setLEDs(0b0000); // --------------------------------------- uint8_t duty_pct = 0; startStopwatch1(); // IMPORTANT: arduio_init(); // ArduIO init!!! writeString_P("\n===> PRESS BUTTON 5 TO STOP THE DEMO!!! <===\n\n"); while(true) { if(getStopwatch1() > 1000) // 1s { // PWM controller test: // LEDs & free PWMs & power PWMs dim UP: writeString("==> DIM Tests: "); writeInteger(duty_pct, DEC); writeString(" % Duty Cycle\n"); dimArduIOLED(1, DUTY_PCT(duty_pct)); dimArduIOLED(2, DUTY_PCT(duty_pct)); dimArduIOLED3(DUTY_PCT(duty_pct)); dimArduIOLED4(DUTY_PCT(duty_pct)); dimArduIOPWM(1, DUTY_PCT(duty_pct)); dimArduIOPWM(2, DUTY_PCT(duty_pct)); dimArduIOPWM3(DUTY_PCT(duty_pct)); dimArduIOPWM4(DUTY_PCT(duty_pct)); dimArduIOPowerPWM(1, DUTY_PCT(duty_pct)); dimArduIOPowerPWM(2, DUTY_PCT(duty_pct)); dimArduIOPowerPWM3(DUTY_PCT(duty_pct)); dimArduIOPowerPWM4(DUTY_PCT(duty_pct)); dimArduIOPowerPWM(5, DUTY_PCT(duty_pct)); dimArduIOPowerPWM(6, DUTY_PCT(duty_pct)); dimArduIOPowerPWM7(DUTY_PCT(duty_pct)); dimArduIOPowerPWM8(DUTY_PCT(duty_pct)); duty_pct += 10; if (duty_pct > 100) { duty_pct = 0; writeString("\n"); } // ArduIO shutdown: uint8_t key = getPressedKeyNumber(); if (key == 5) { writeString("\nPress button 1 for ArduIO SHUTDOWN"); writeString("\nor button 2, 3 or 4 to continue!!!\n"); do { mSleep(10); key = getPressedKeyNumber(); } while ((!key) || (key == 5)); if (key == 1) { writeString("\nPlease wait for ArduIO SHUTDOWN...\n"); arduio_shutdown(); mSleep(3000); writeString("\nThe ArduIO now is in SHUTDOWN MODE!!!\n"); mSleep(1000); writeString("\nRESET the microcontroller now...\n\n"); while(true) {}; } } setStopwatch1(0); } task_I2CTWI(); } return 0; }
Erklärung
Demo 3
Datei RP6Control_ArduIO_03.c:
Erklärung
RP6 BASE
Die Demos für die RP6(v2) Base (und -wenn ihr wollt- auch eure eigenen Programme) nutzen die ArduIO Library, s.o.!
Config
Diese Datei enthält nur die Information, welches RP6-Mikrocontroller-System (RP6 Base, RP6 CONTROL M32, RP6 M256 WiFi) das ArduIO Board ansteuert. Sie gehört in den Projektordner.
Datei RP6_ArduIOConfig.h:
/** * Settings for the RP6_ArduIO Library */ #ifndef RP6_ARDUIOCONFIG_H #define RP6_ARDUIOCONFIG_H /** * Define the target here: * (Use only ONE of them! Never two or three!) */ #define ARDUIO_RP6BASE //#define ARDUIO_RP6CONTROL //#define ARDUIO_RP6M256WIFI #endif
makefile (z.B. für Demo 1):
... TARGET = RP6Base_ArduIO_01 ... SRC += $(RP6_LIB_PATH)/RP6common/RP6_ArduIOLib.c ...
Demos der M32 anpassen
Es ist einfach, die M32 Demos an die RP6 Base anzupassen. Die ArduIO Library braucht nicht verändert zu werden.
Folgende Anpassungen müssen gemacht werden:
- #include "RP6ControlLib.h" ==> #include "RP6RobotBaseLib.h" - initRP6Control(); ==> initRobotBase(); - initLCD(); ==> LCD-Ausgaben komplett entfernen! - ==> powerON(); - setLEDs(0b1111); ==> setLEDs(0b111111); - getPressedKeyNumber() ==> Tastenabfrage komplett entfernen!
RP6 CCPRO M128
Für die CCPRO M128 soll es hier evtl. eine eigene ArduIO Library geben. Die nachfolgenden Demos nutzen diese Library.
ArduIO Library
Schauen wir mal, ob es hier eine ArduIO Library für die CCPRO M128 geben wird. Das hängt sicher auch davon ab, ob einer der Nutzer das ArduIO Board mit der M128 betreiben will.
Erklärung
Demo 1
Erklärung
Demo 2
Erklärung
Demo 3
Erklärung
Arduino UNO
Das Ardu IO Projekt Board (= "ArduIO") ist nicht nur eine RP6 Erweiterungsplatine, sondern auch ein Arduino Shield. Damit stellt die ArduIO eine Verbindung zwischen dem RP6-System und der "Arduino-Welt" dar. Als Arduino Shield kann die ArduIO auf eine Arduino UNO Platine gesteckt werden, die dann alle Funktionen der ArduIO steuern kann. Weitere Arduino Shields können wiederum auf die ArduIO gesteckt werden. Die Verbindung zum RP6-System kann dann über die XBUS- und USRBUS-Stecker der ArduIO erfolgen.
ArduIO Library
Die Library (Software-Bibliothek) besteht aus drei Teilen:
- Dem Library Header -> Hier gibt es Definitionen, Variablen- und Funktionsdeklarationen für die Library.
- Der Library Source -> Das ist die eigentliche Library.
- Der Datei keywords.txt -> Hier stehen alle Bezeichnungen, die im Editor der Arduino IDE markiert (farblich hervorgehoben) werden.
Die Dateien dieser Arduino Library gehören ins Verzeichnis /.../libraries/RP6_ArduIO/.
Library Header
Datei RP6_ArduIO.h:
Library Source
Datei RP6_ArduIO.cpp:
Library Keywords
Datei keywords.txt:
####################################### # Syntax Coloring Map For RP6_ArduIO ####################################### ####################################### # Datatypes, Classes & C++ Keywords # (KEYWORD1) ####################################### RP6_ArduIO KEYWORD1 arduio KEYWORD1 status_t KEYWORD1 ioexp_1_t KEYWORD1 ioexp_2_t KEYWORD1 ioexp_3_t KEYWORD1 addaexp_1_t KEYWORD1 addaexp_2_t KEYWORD1 addaexp_3_t KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### enableHB KEYWORD2 disableHB KEYWORD2 enablePPWM_G KEYWORD2 disablePPWM_G KEYWORD2 enablePWMs KEYWORD2 disablePWMs KEYWORD2 enableOuts KEYWORD2 disableOuts KEYWORD2 enableDAs KEYWORD2 disableDAs KEYWORD2 PCA9685_init KEYWORD2 PCA9685_set KEYWORD2 config_IO KEYWORD2 update_IO KEYWORD2 set_IO KEYWORD2 invert_IO KEYWORD2 read_IO KEYWORD2 read_AD KEYWORD2 write_DA KEYWORD2 disable_DA KEYWORD2 getUbSensor KEYWORD2 calculateUb KEYWORD2 measureUb KEYWORD2 setLEDs KEYWORD2 dimLED KEYWORD2 setLED1 KEYWORD2 setLED2 KEYWORD2 setLED3 KEYWORD2 setLED4 KEYWORD2 setPWMs KEYWORD2 dimPWM KEYWORD2 setPWM1 KEYWORD2 setPWM2 KEYWORD2 setPWM3 KEYWORD2 setPWM4 KEYWORD2 setPowerPWMMode KEYWORD2 setPowerPWMs KEYWORD2 dimPowerPWM KEYWORD2 setPowerPWM1 KEYWORD2 setPowerPWM2 KEYWORD2 setPowerPWM3 KEYWORD2 setPowerPWM4 KEYWORD2 setPowerPWM5 KEYWORD2 setPowerPWM6 KEYWORD2 setPowerPWM7 KEYWORD2 setPowerPWM8 KEYWORD2 adjustPowerHB KEYWORD2 readSystem KEYWORD2 init KEYWORD2 shutdown KEYWORD2 updateArduino_Uno_Exp_IO KEYWORD2 setArduino_Uno_Exp_IO KEYWORD2 readArduino_Uno_Exp KEYWORD2 ####################################### # Setup & Loop Functions, the Serial # Keywords (KEYWORD3) ####################################### ####################################### # Constants (LITERAL1) ####################################### PWM_FREQUENCY LITERAL1 ADCVAL_UB_LOW LITERAL1 DISABLE_ON_SHUTDOWN LITERAL1 READ_ADCUB LITERAL1 DUTY_0 LITERAL1 DUTY_10 LITERAL1 DUTY_25 LITERAL1 DUTY_50 LITERAL1 DUTY_75 LITERAL1 DUTY_90 LITERAL1 DUTY_100 LITERAL1 FWD LITERAL1 BWD LITERAL1 BRK LITERAL1 OFF LITERAL1 ####################################### # Built-in Variables (LITERAL2) #######################################
Erklärung
Demo 1
Erklärung
Demo 2
Erklärung
Demo 3
Erklärung
Technische Informationen
I2C-Adressen
I2C-Adressen der ArduIO:
I2C-Portexpander-Baustein | I2C- Adresse * |
Alternative I2C-Adressen | Verwendung |
I2C PWM Controller (IC3: PCA9685) | 0x84 | 0x86, 0x8c, 0x8e, 0xe0 | PWM Controller |
I2C I/O Expander 1 5V (IC8: PCA9535) | 0x44 | 0x46, 0x4c, 0x4e | I/O Expander 1 |
I2C I/O Expander 2 5V (IC13: PCA9535) | 0x46 | 0x44, 0x4c, 0x4e | I/O Expander 2 |
I2C I/O Expander 3 3V3 (IC12: PCA9535) | 0x4c | 0x44, 0x46, 0x4e | I/O Expander 3 |
I2C A/D und D/A Converter 1 (IC11: PCF8591) | 0x94 | 0x96, 0x9c, 0x9e | A/D und D/A Converter 1 |
I2C A/D und D/A Converter 2 (IC10: PCF8591) | 0x96 | 0x94, 0x9c, 0x9e | A/D und D/A Converter 2 |
I2C A/D und D/A Converter 3 (IC9: PCF8591) | 0x9c | 0x94, 0x96, 0x9e | A/D und D/A Converter 3 |
Zu *) Standard-Adresse.
Zu ²) Adress-Konflikt mit dem RP6-System möglich (siehe hier)!
Stecker-Belegungen
Siehe auch
- RP6v2
- RP6
- RP6 - Programmierung
- RP6_Sensor_Board_und_Xtra_Module
- RP6 Kamera - Mitmach-Projekt
- RP6v2 I2C-Portexpander
- RP6v2 USB-RS232-Adapter
- RP6v2 Orientierung
- RP6 Multi IO Projekt
- RP6 Multi IO Projekt - Software
- RP6 ArduIO
- Induktive Ladestation für den RP6
- IR-bake für den RP6
- CCRP5
- Yeti
- Asuro
- C't-Bot
Weblinks
Umfangreiche Dokumentation, sämtliche Beispielprogramme und Bibliotheken, Daten, Teilelisten und eine Lötanleitung finden sich HIER.
HIER findet ihr den Hardware-Artikel.
Autoren
--Dirk 19:53, 22. Nov 2014 (CET)