Aus RN-Wissen.de
Wechseln zu: Navigation, Suche
Laderegler Test Tueftler Seite

K (Library Header)
K (Autoren)
Zeile 2.995: Zeile 2.995:
  
 
==Autoren==
 
==Autoren==
--[http://www.roboternetz.de/community/members/1972-Dirk Dirk] 12:27, 23. Nov 2014 (CET)
+
--[http://www.roboternetz.de/community/members/1972-Dirk Dirk] 13:07, 23. Nov 2014 (CET)

Version vom 23. November 2014, 13:07 Uhr

RP6 ArduIO V1.0

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

ArduIO Jumper Standardstellung 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:

/* ****************************************************************************
 *                           _______________________
 *                           \| RP6  ROBOT SYSTEM |/
 *                            \_-_-_-_-_-_-_-_-_-_/                  >>> COMMON
 * ----------------------------------------------------------------------------
 * ----------------------------- [c]2014 - Dirk -------------------------------
 * ****************************************************************************
 * File: RP6_ArduIOLib.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:
 * This is the RP6_ArduIOLib header file.
 * You have to include this file, if you want to use the library
 * RP6_ArduIOLib.c in your own projects.
 *
 * ****************************************************************************
 * THE CHANGELOG CAN BE FOUND AT THE END OF THIS FILE!
 * ****************************************************************************
 */

#ifndef RP6_ARDUIOLIB_H
#define RP6_ARDUIOLIB_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_ArduIO.h"				// Config. header for ArduIO Library

// Select includes depending on RP6_ArduIOConfig.h:
#ifdef ARDUIO_RP6BASE
	#include "RP6RobotBaseLib.h"	// The RP6 Robot Base Library.
#else
#ifdef ARDUIO_RP6CONTROL
	#include "RP6ControlLib.h"		// The RP6 Control M32 Library.
#else
#ifdef ARDUIO_RP6M256WIFI
	#include "RP6M256Lib.h" 		// The RP6 M256 Library.
#else
	#error DEFINE "ARDUIO_RP6BASE", "ARDUIO_RP6CONTROL" OR "ARDUIO_RP6M256WIFI"
	#error AS TARGET IN RP6_ArduIOConfig.h
#endif
#endif
#endif
#include "RP6I2CmasterTWI.h"		// Include the I2C-Bus Master Library

/*****************************************************************************/
// ArduIO Status:

#define DISABLE_ON_SHUTDOWN				// Disable access to PPWM, PWM, Out
										// & DAC ports in SHUTDOWN mode
										// (default)!

// The ArduIO status bits with access settings & UB voltage low flag:
typedef union {
 	uint8_t byte;
	struct {
		unsigned ubatLow       :1;		// UB voltage low
		unsigned hb1Enable     :1;		// H-Bridge 1 (HB1) enable
		unsigned hb2Enable     :1;		// H-Bridge 2 (HB2) enable
		unsigned ppwm_g1Enable :1;		// Power PWM group 1 (PPWM1..4) enable
		unsigned ppwm_g2Enable :1;		// Power PWM group 2 (PPWM5..8) enable
		unsigned pwmsEnable    :1;		// Free PWMs (PWM1..4) enable
		unsigned outsEnable    :1;		// IO_1..3 IOs enable as outputs
		unsigned dasEnable     :1;		// ADDA_1..3 DACs enable
	};
} RP6ArduIOstatus_t;

extern RP6ArduIOstatus_t RP6ArduIOstatus;	// ArduIO status bits (read only)

void enableHB(uint8_t);
#define enableHB1() {enableHB(1);}
#define enableHB2() {enableHB(2);}
#define isHB1Enable() (RP6ArduIOstatus_LIB.byte & 2)
#define isHB2Enable() (RP6ArduIOstatus_LIB.byte & 4)
void disableHB(uint8_t);
#define disableHB1() {disableHB(1);}
#define disableHB2() {disableHB(2);}
void enablePPWM_G(uint8_t);
#define enablePPWM_G1() {enablePPWM_G(1);}
#define enablePPWM_G2() {enablePPWM_G(2);}
#define isPPWM_G1Enable() (RP6ArduIOstatus_LIB.byte & 8)
#define isPPWM_G2Enable() (RP6ArduIOstatus_LIB.byte & 16)
void disablePPWM_G(uint8_t);
#define disablePPWM_G1() {disablePPWM_G(1);}
#define disablePPWM_G2() {disablePPWM_G(2);}
void enablePWMs(void);
#define isPWMsEnable() (RP6ArduIOstatus_LIB.byte & 32)
void disablePWMs(void);
void enableOuts(void);
#define isOutsEnable() (RP6ArduIOstatus_LIB.byte & 64)
void disableOuts(void);
void enableDAs(void);
#define isDAsEnable() (RP6ArduIOstatus_LIB.byte & 128)
void disableDAs(void);
#define setArduIODefaultStatus() {enablePPWM_G(1);enablePPWM_G(2); \
 enablePWMs();enableOuts();enableDAs();}
#define setArduIOShutdownStatus() {disableHB(1);disableHB(2); \
 disablePPWM_G(1);disablePPWM_G(2);disablePWMs();disableOuts();disableDAs();}

/*****************************************************************************/
// I2C PWM Controller (PCA9685):

// Registers:
#define PCA9685_MODE1					0
#define PCA9685_MODE2					1
#define PCA9685_SUBADR1					2
#define PCA9685_SUBADR2					3
#define PCA9685_SUBADR3					4
#define PCA9685_ALLCALLADR				5
#define PCA9685_LED0_ON_L				6
#define PCA9685_LED0_ON_H				7
#define PCA9685_LED0_OFF_L				8
#define PCA9685_LED0_OFF_H				9
#define PCA9685_LED1_ON_L				10
#define PCA9685_LED1_ON_H				11
#define PCA9685_LED1_OFF_L				12
#define PCA9685_LED1_OFF_H				13
#define PCA9685_LED2_ON_L				14
#define PCA9685_LED2_ON_H				15
#define PCA9685_LED2_OFF_L				16
#define PCA9685_LED2_OFF_H				17
#define PCA9685_LED3_ON_L				18
#define PCA9685_LED3_ON_H				19
#define PCA9685_LED3_OFF_L				20
#define PCA9685_LED3_OFF_H				21
#define PCA9685_LED4_ON_L				22
#define PCA9685_LED4_ON_H				23
#define PCA9685_LED4_OFF_L				24
#define PCA9685_LED4_OFF_H				25
#define PCA9685_LED5_ON_L				26
#define PCA9685_LED5_ON_H				27
#define PCA9685_LED5_OFF_L				28
#define PCA9685_LED5_OFF_H				29
#define PCA9685_LED6_ON_L				30
#define PCA9685_LED6_ON_H				31
#define PCA9685_LED6_OFF_L				32
#define PCA9685_LED6_OFF_H				33
#define PCA9685_LED7_ON_L				34
#define PCA9685_LED7_ON_H				35
#define PCA9685_LED7_OFF_L				36
#define PCA9685_LED7_OFF_H				37
#define PCA9685_LED8_ON_L				38
#define PCA9685_LED8_ON_H				39
#define PCA9685_LED8_OFF_L				40
#define PCA9685_LED8_OFF_H				41
#define PCA9685_LED9_ON_L				42
#define PCA9685_LED9_ON_H				43
#define PCA9685_LED9_OFF_L				44
#define PCA9685_LED9_OFF_H				45
#define PCA9685_LED10_ON_L				46
#define PCA9685_LED10_ON_H				47
#define PCA9685_LED10_OFF_L				48
#define PCA9685_LED10_OFF_H				49
#define PCA9685_LED11_ON_L				50
#define PCA9685_LED11_ON_H				51
#define PCA9685_LED11_OFF_L				52
#define PCA9685_LED11_OFF_H				53
#define PCA9685_LED12_ON_L				54
#define PCA9685_LED12_ON_H				55
#define PCA9685_LED12_OFF_L				56
#define PCA9685_LED12_OFF_H				57
#define PCA9685_LED13_ON_L				58
#define PCA9685_LED13_ON_H				59
#define PCA9685_LED13_OFF_L				60
#define PCA9685_LED13_OFF_H				61
#define PCA9685_LED14_ON_L				62
#define PCA9685_LED14_ON_H				63
#define PCA9685_LED14_OFF_L				64
#define PCA9685_LED14_OFF_H				65
#define PCA9685_LED15_ON_L				66
#define PCA9685_LED15_ON_H				67
#define PCA9685_LED15_OFF_L				68
#define PCA9685_LED15_OFF_H				69
#define PCA9685_ALL_LED_ON_L			250
#define PCA9685_ALL_LED_ON_H			251
#define PCA9685_ALL_LED_OFF_L			252
#define PCA9685_ALL_LED_OFF_H			253
#define PCA9685_PRE_SCALE				254
#define PCA9685_TESTMODE				255

// Mode1 register bitmasks:
#define PCA9685_MODE1_DEFAULT			17
#define PCA9685_MODE1_ALLCALL			1
#define PCA9685_MODE1_SUB3				2
#define PCA9685_MODE1_SUB2				4
#define PCA9685_MODE1_SUB1				8
#define PCA9685_MODE1_SLEEP				16
#define PCA9685_MODE1_AI				32
#define PCA9685_MODE1_EXTCLK			64
#define PCA9685_MODE1_RESTART			128

// Mode2 register bitmasks:
#define PCA9685_MODE2_DEFAULT			4		// Totem poles (default)
#define PCA9685_MODE2_ARDUIO			16		// Inverted open-drains
#define PCA9685_MODE2_OUTDRV			4
#define PCA9685_MODE2_OCH				8
#define PCA9685_MODE2_INVRT				16

#define F_PCA9685						25000000.0	// Int. Clock: 25 MHz

void PCA9685_init(uint16_t);
#define initPWM(__FREQ__) {PCA9685_init(__FREQ__);}
void PCA9685_set(uint8_t, uint16_t);
#define setPWM(__CHANNEL__,__DUTY__) {PCA9685_set(__CHANNEL__,__DUTY__);}

/*****************************************************************************/
// I2C I/O Expander (PCF9535):

// Registers:
#define PCA9535_INPUT_P0				0
#define PCA9535_INPUT_P1				1
#define PCA9535_OUTPUT_P0				2
#define PCA9535_OUTPUT_P1				3
#define PCA9535_POL_INV_P0				4
#define PCA9535_POL_INV_P1				5
#define PCA9535_CONFIG_P0				6
#define PCA9535_CONFIG_P1				7

// I2C I/O Expander 1 5V (IC8: PCA9535):
#define IO_1							1
typedef union {
	uint16_t word;
	struct {
		unsigned P00:1;					// P00
		unsigned P01:1;					// P01
		unsigned P02:1;					// P02
		unsigned P03:1;					// P03
		unsigned P04:1;					// P04
		unsigned P05:1;					// P05
		unsigned P06:1;					// P06
		unsigned P07:1;					// P07
		unsigned P10:1;					// P10
		unsigned P11:1;					// P11
		unsigned P12:1;					// P12
		unsigned P13:1;					// P13
		unsigned P14:1;					// P14
		unsigned P15:1;					// P15
		unsigned P16:1;					// P16
		unsigned P17:1;					// P17
	};
	struct {
		unsigned GP100:1;				// IO_1: P00
		unsigned GP101:1;				// IO_1: P01
		unsigned GP102:1;				// IO_1: P02
		unsigned GP103:1;				// IO_1: P03
		unsigned GP104:1;				// IO_1: P04
		unsigned GP105:1;				// IO_1: P05
		unsigned GP106:1;				// IO_1: P06
		unsigned GP107:1;				// IO_1: P07
		unsigned GP110:1;				// IO_1: P10
		unsigned GP111:1;				// IO_1: P11
		unsigned GP112:1;				// IO_1: P12
		unsigned GP113:1;				// IO_1: P13
		unsigned GP114:1;				// IO_1: P14
		unsigned GP115:1;				// IO_1: P15
		unsigned GP116:1;				// IO_1: P16
		unsigned GP117:1;				// IO_1: P17
	};
} ioexp_1_t;

extern ioexp_1_t io1config;
extern ioexp_1_t io1invrt;
extern ioexp_1_t io1ins;
extern ioexp_1_t io1outs;

// I2C I/O Expander 2 5V (IC13: PCA9535):
#define IO_2							2
typedef union {
	uint16_t word;
	struct {
		unsigned P00:1;					// P00
		unsigned P01:1;					// P01
		unsigned P02:1;					// P02
		unsigned P03:1;					// P03
		unsigned P04:1;					// P04
		unsigned P05:1;					// P05
		unsigned P06:1;					// P06
		unsigned P07:1;					// P07
		unsigned P10:1;					// P10
		unsigned P11:1;					// P11
		unsigned P12:1;					// P12
		unsigned P13:1;					// P13
		unsigned P14:1;					// P14
		unsigned P15:1;					// P15
		unsigned P16:1;					// P16
		unsigned P17:1;					// P17
	};
	struct {
		unsigned GP200:1;				// IO_2: P00
		unsigned GP201:1;				// IO_2: P01
		unsigned GP202:1;				// IO_2: P02
		unsigned GP203:1;				// IO_2: P03
		unsigned GP204:1;				// IO_2: P04
		unsigned GP205:1;				// IO_2: P05
		unsigned GP206:1;				// IO_2: P06
		unsigned GP207:1;				// IO_2: P07
		unsigned GP210:1;				// IO_2: P10
		unsigned GP211:1;				// IO_2: P11
		unsigned GP212:1;				// IO_2: P12
		unsigned GP213:1;				// IO_2: P13
		unsigned GP214:1;				// IO_2: P14
		unsigned GP215:1;				// IO_2: P15
		unsigned GP216:1;				// IO_2: P16
		unsigned GP217:1;				// IO_2: P17
	};
	struct {
		unsigned ARD_D0:1;				// ARD: D0
		unsigned ARD_D1:1;				// ARD: D1
		unsigned ARD_D2:1;				// ARD: D2
		unsigned ARD_D3:1;				// ARD: D3
		unsigned ARD_D4:1;				// ARD: D4
		unsigned ARD_D5:1;				// ARD: D5
		unsigned ARD_D6:1;				// ARD: D6
		unsigned ARD_D7:1;				// ARD: D7
		unsigned ARD_D13:1;				// ARD: D13
		unsigned ARD_D12:1;				// ARD: D12
		unsigned ARD_D11:1;				// ARD: D11
		unsigned ARD_D10:1;				// ARD: D10
		unsigned ARD_D9:1;				// ARD: D9
		unsigned ARD_D8:1;				// ARD: D8
		unsigned GP216:1;				// IO_2: P16
		unsigned GP217:1;				// IO_2: P17
	};
} ioexp_2_t;

extern ioexp_2_t io2config;
extern ioexp_2_t io2invrt;
extern ioexp_2_t io2ins;
extern ioexp_2_t io2outs;

// I2C I/O Expander 3 3V3 (IC12: PCA9535):
#define IO_3							3
typedef union {
	uint16_t word;
	struct {
		unsigned P00:1;					// P00
		unsigned P01:1;					// P01
		unsigned P02:1;					// P02
		unsigned P03:1;					// P03
		unsigned P04:1;					// P04
		unsigned P05:1;					// P05
		unsigned P06:1;					// P06
		unsigned P07:1;					// P07
		unsigned P10:1;					// P10
		unsigned P11:1;					// P11
		unsigned P12:1;					// P12
		unsigned P13:1;					// P13
		unsigned P14:1;					// P14
		unsigned P15:1;					// P15
		unsigned P16:1;					// P16
		unsigned P17:1;					// P17
	};
	struct {
		unsigned GP300:1;				// IO_3: P00
		unsigned GP301:1;				// IO_3: P01
		unsigned GP302:1;				// IO_3: P02
		unsigned GP303:1;				// IO_3: P03
		unsigned GP304:1;				// IO_3: P04
		unsigned GP305:1;				// IO_3: P05
		unsigned GP306:1;				// IO_3: P06
		unsigned GP307:1;				// IO_3: P07
		unsigned GP310:1;				// IO_3: P10
		unsigned GP311:1;				// IO_3: P11
		unsigned GP312:1;				// IO_3: P12
		unsigned GP313:1;				// IO_3: P13
		unsigned GP314:1;				// IO_3: P14
		unsigned GP315:1;				// IO_3: P15
		unsigned GP316:1;				// IO_3: P16
		unsigned GP317:1;				// IO_3: P17
	};
} ioexp_3_t;

extern ioexp_3_t io3config;
extern ioexp_3_t io3invrt;
extern ioexp_3_t io3ins;
extern ioexp_3_t io3outs;

// I2C I/O Expander (PCA9535) interrupt status bits:
typedef union {
 	uint8_t byte;
	struct {
		unsigned int1    :1;			// INT1  XBUS Pin 8
		unsigned int2    :1;			// INT2  XBUS Pin 11
		unsigned int3    :1;			// INT3  XBUS Pin 9
		unsigned intu    :1;			// INTU  XBUS Pin 7
		unsigned unused  :4;
	};
	struct {
		unsigned ioexp_2 :1;			// INT1: PCA9535 (2) INT
		unsigned ioexp_1 :1;			// INT2: PCA9535 (1) INT
		unsigned ioexp_3 :1;			// INT3: PCA9535 (3) INT
		unsigned noname  :5;
	};
} interrupt_RP6ArduIOstatus_t;

extern interrupt_RP6ArduIOstatus_t interrupt_RP6ArduIOstatus;
extern uint8_t interrupt_rp6arduiostatus_changed;

// I2C I/O Expander (PCA9535) general functions:
void configArduIO_IO(uint8_t, uint16_t);
#define configArduIO_IO1(__INOUT__) {configArduIO_IO(1,__INOUT__);}
#define configArduIO_IO2(__INOUT__) {configArduIO_IO(2,__INOUT__);}
#define configArduIO_IO3(__INOUT__) {configArduIO_IO(3,__INOUT__);}
void updateArduIO_IO(uint8_t);
#define updateArduIO_IO1() {updateArduIO_IO(1);}
#define updateArduIO_IO2() {updateArduIO_IO(2);}
#define updateArduIO_IO3() {updateArduIO_IO(3);}
void setArduIO_IO(uint8_t, uint16_t);
#define setArduIO_IO1(__OUT__) {setArduIO_IO(1,__OUT__);}
#define setArduIO_IO2(__OUT__) {setArduIO_IO(2,__OUT__);}
#define setArduIO_IO3(__OUT__) {setArduIO_IO(3,__OUT__);}
void invertArduIO_IO(uint8_t, uint16_t);
#define invertArduIO_IO1(__INVRT__) {invertArduIO_IO(1,__INVRT__);}
#define invertArduIO_IO2(__INVRT__) {invertArduIO_IO(2,__INVRT__);}
#define invertArduIO_IO3(__INVRT__) {invertArduIO_IO(3,__INVRT__);}
void task_readArduIO_IO(uint8_t);
#define task_readArduIO_IO1() {task_readArduIO_IO(1);}
#define task_readArduIO_IO2() {task_readArduIO_IO(2);}
#define task_readArduIO_IO3() {task_readArduIO_IO(3);}
#define task_readAllArduIO_IOs() {task_readArduIO_IO(1); \
 task_readArduIO_IO(2);task_readArduIO_IO(3);}
void task_checkArduIO_INTs(void);
#define int_status_changed() (interrupt_rp6arduiostatus_changed)

/*****************************************************************************/
// I2C A/D and D/A Converter (PCF8591):

#define READ_ADCUB	// If defined: Function task_readArduIO_AD(1) will also
					//  (default)  read the UB voltage ADC value (adcub) and
					//             will update the UB voltage low condition
					//             flag (RP6ArduIOstatus.ubatLow)!
					// If NOT defined: The UB voltage ADC value can be found
					//                 in the variable ad1ins.ArduIO_UB after
					//                 execution of task_readArduIO_AD(1)!
					// READ_ADCUB should NOT be defined, if jumper JP_AD-UB
					// on the ArduIO Board is OPEN!

// Control Byte bitmasks:
#define PCF8591_CONTROL_DEFAULT			0
#define PCF8591_CONTROL_ARDUIO			0b01000100	// Auto-increment & DAC

#define PCF8591_CONTROL_AUTO_INC		4			// Auto-increment
#define PCF8591_CONTROL_DAC_ENABLE		64			// DAC enable

// I2C A/D and D/A Converter 1 (IC11: PCF8591):
#define ADDA_1							1
typedef union {
	struct {
		uint8_t AIN0;					// AIN0
		uint8_t AIN1;					// AIN1
		uint8_t AIN2;					// AIN2
		uint8_t AIN3;					// AIN3
	};
	struct {
		uint8_t AD10;					// ADDA_1: AIN0
		uint8_t AD11;					// ADDA_1: AIN1
		uint8_t AD12;					// ADDA_1: AIN2
		uint8_t AD13;					// ADDA_1: AIN3
	};
	struct {
		uint8_t AD10;					// ADDA_1: AIN0
		uint8_t AD11;					// ADDA_1: AIN1
		uint8_t AD12;					// ADDA_1: AIN2
		uint8_t ArduIO_UB;				// ArduIO: UB
	};
} addaexp_1_t;

extern addaexp_1_t ad1ins;

// I2C A/D and D/A Converter 2 (IC10: PCF8591):
#define ADDA_2							2
typedef union {
	struct {
		uint8_t AIN0;					// AIN0
		uint8_t AIN1;					// AIN1
		uint8_t AIN2;					// AIN2
		uint8_t AIN3;					// AIN3
	};
	struct {
		uint8_t AD20;					// ADDA_2: AIN0
		uint8_t AD21;					// ADDA_2: AIN1
		uint8_t AD22;					// ADDA_2: AIN2
		uint8_t AD23;					// ADDA_2: AIN3
	};
} addaexp_2_t;

extern addaexp_2_t ad2ins;

// I2C A/D and D/A Converter 3 (IC9: PCF8591):
#define ADDA_3							3
typedef union {
	struct {
		uint8_t AIN0;					// AIN0
		uint8_t AIN1;					// AIN1
		uint8_t AIN2;					// AIN2
		uint8_t AIN3;					// AIN3
	};
	struct {
		uint8_t AD30;					// ADDA_3: AIN0
		uint8_t AD31;					// ADDA_3: AIN1
		uint8_t AD32;					// ADDA_3: AIN2
		uint8_t AD33;					// ADDA_3: AIN3
	};
	struct {
		uint8_t ARD_A0;					// ARD: A0
		uint8_t ARD_A1;					// ARD: A1
		uint8_t ARD_A2;					// ARD: A2
		uint8_t ARD_A3;					// ARD: A3
	};
} addaexp_3_t;

extern addaexp_3_t ad3ins;

// I2C A/D and D/A Converter (PCF8591) general functions:
#define UCV_AD(__AD__) (uint16_t)(__AD__*500.0f/255.0f)

void task_readArduIO_AD(uint8_t);
#define task_readArduIO_AD1() {task_readArduIO_AD(1);}
#define task_readArduIO_AD2() {task_readArduIO_AD(2);}
#define task_readArduIO_AD3() {task_readArduIO_AD(3);}
#define task_readAllArduIO_ADs() {task_readArduIO_AD(1); \
 task_readArduIO_AD(2);task_readArduIO_AD(3);}

#define AOUT_CV(__CV__) (uint8_t)(__CV__*0.51f)

extern uint8_t da1aout;
extern uint8_t da2aout;
extern uint8_t da3aout;

void writeArduIO_DA(uint8_t, uint8_t);
#define writeArduIO_DA1(__AOUT__) {writeArduIO_DA(1,__AOUT__);}
#define writeArduIO_DA2(__AOUT__) {writeArduIO_DA(2,__AOUT__);}
#define writeArduIO_DA3(__AOUT__) {writeArduIO_DA(3,__AOUT__);}
void disableArduIO_DA(uint8_t);
#define disableArduIO_DA1() {disableArduIO_DA(1);}
#define disableArduIO_DA2() {disableArduIO_DA(2);}
#define disableArduIO_DA3() {disableArduIO_DA(3);}
#define disableAllArduIO_DAs() {disableArduIO_DA(1); \
 disableArduIO_DA(2);disableArduIO_DA(3);}

/*****************************************************************************/
// UB Voltage Sensor:

extern uint8_t adcub;
extern double ubv;

uint8_t getUbSensor(void);
double calculateUb(void);
double measureUb(void);
#define isUbLow() (RP6ArduIOstatus_LIB.byte & 1)

/*****************************************************************************/
// LEDs:

// --------------------------------------------------------------
// Duty cycle constants:
#define DUTY_0							0		// 0%
#define DUTY_10							409		// 10%
#define DUTY_25							1023	// 25%
#define DUTY_50							2047	// 50%
#define DUTY_75							3071	// 75%
#define DUTY_90							3685	// 90%
#define DUTY_100						4095	// 100%
// Relative duty cycle [__PCT__ = 0..100%] macro:
#define DUTY_PCT(__PCT__) (uint16_t)((uint32_t)__PCT__*4095/100)
// --------------------------------------------------------------

void setArduIOLEDs(uint8_t);

void dimArduIOLED(uint8_t, uint16_t);
#define dimArduIOLED1(__DUTY__) {dimArduIOLED(1,__DUTY__);}
#define dimArduIOLED2(__DUTY__) {dimArduIOLED(2,__DUTY__);}
#define dimArduIOLED3(__DUTY__) {dimArduIOLED(3,__DUTY__);}
#define dimArduIOLED4(__DUTY__) {dimArduIOLED(4,__DUTY__);}
void setArduIOLED1(uint8_t);
void setArduIOLED2(uint8_t);
void setArduIOLED3(uint8_t);
void setArduIOLED4(uint8_t);

/*****************************************************************************/
// PWM Ports:

void setArduIOPWMs(uint8_t);

void dimArduIOPWM(uint8_t, uint16_t);
#define dimArduIOPWM1(__DUTY__) {dimArduIOPWM(1,__DUTY__);}
#define dimArduIOPWM2(__DUTY__) {dimArduIOPWM(2,__DUTY__);}
#define dimArduIOPWM3(__DUTY__) {dimArduIOPWM(3,__DUTY__);}
#define dimArduIOPWM4(__DUTY__) {dimArduIOPWM(4,__DUTY__);}
void setArduIOPWM1(uint8_t);
void setArduIOPWM2(uint8_t);
void setArduIOPWM3(uint8_t);
void setArduIOPWM4(uint8_t);

/*****************************************************************************/
// Power PWM Ports & H-Bridges:

// Power PWM Ports:
void setArduIOPowerPWMMode(void);
void setArduIOPowerPWMs(uint8_t);

void dimArduIOPowerPWM(uint8_t, uint16_t);
#define dimArduIOPowerPWM1(__DUTY__) {dimArduIOPowerPWM(1,__DUTY__);}
#define dimArduIOPowerPWM2(__DUTY__) {dimArduIOPowerPWM(2,__DUTY__);}
#define dimArduIOPowerPWM3(__DUTY__) {dimArduIOPowerPWM(3,__DUTY__);}
#define dimArduIOPowerPWM4(__DUTY__) {dimArduIOPowerPWM(4,__DUTY__);}
#define dimArduIOPowerPWM5(__DUTY__) {dimArduIOPowerPWM(5,__DUTY__);}
#define dimArduIOPowerPWM6(__DUTY__) {dimArduIOPowerPWM(6,__DUTY__);}
#define dimArduIOPowerPWM7(__DUTY__) {dimArduIOPowerPWM(7,__DUTY__);}
#define dimArduIOPowerPWM8(__DUTY__) {dimArduIOPowerPWM(8,__DUTY__);}
void setArduIOPowerPWM1(uint8_t);
void setArduIOPowerPWM2(uint8_t);
void setArduIOPowerPWM3(uint8_t);
void setArduIOPowerPWM4(uint8_t);
void setArduIOPowerPWM5(uint8_t);
void setArduIOPowerPWM6(uint8_t);
void setArduIOPowerPWM7(uint8_t);
void setArduIOPowerPWM8(uint8_t);

// H-Bridges:

// ------------------------------------------------------------
// Direction/command:
#ifndef FWD
#define FWD								0		// Forwards
#define BWD								1		// Backwards
#endif
#define BRK								4		// Speed break
#define OFF								5		// Power OFF
// ------------------------------------------------------------

void adjustArduIOPowerHB(uint8_t hb, uint8_t dir, uint16_t duty);
#define powerHB1(__DIR__,__DUTY__) {adjustArduIOPowerHB(1,__DIR__,__DUTY__);}
#define powerHB1STOP() {adjustArduIOPowerHB(1,FWD,DUTY_0);}
#define powerHB1FWD(__DUTY__) {adjustArduIOPowerHB(1,FWD,__DUTY__);}
#define powerHB1BWD(__DUTY__) {adjustArduIOPowerHB(1,BWD,__DUTY__);}
#define powerHB1BRK() {adjustArduIOPowerHB(1,BRK,0);}
#define powerHB1OFF() {adjustArduIOPowerHB(1,OFF,0);}
#define powerHB2(__DIR__,__DUTY__) {adjustArduIOPowerHB(2,__DIR__,__DUTY__);}
#define powerHB2STOP() {adjustArduIOPowerHB(2,FWD,DUTY_0);}
#define powerHB2FWD(__DUTY__) {adjustArduIOPowerHB(2,FWD,__DUTY__);}
#define powerHB2BWD(__DUTY__) {adjustArduIOPowerHB(2,BWD,__DUTY__);}
#define powerHB2BRK() {adjustArduIOPowerHB(2,BRK,0);}
#define powerHB2OFF() {adjustArduIOPowerHB(2,OFF,0);}

/*****************************************************************************/
// ArduIO Board system control routine:

void task_RP6_ArduIOSystem(void);

/*****************************************************************************/
// ArduIO Board initialisation and shutdown:

void arduio_init(void);
void arduio_shutdown(void);

/*****************************************************************************/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*                      Arduino Uno Expander functions                       */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void updateArduino_Uno_Exp_IO(void);
void setArduino_Uno_Exp_IO(uint16_t);
#define task_readArduino_Uno_Exp_IO() {task_readArduIO_IO(2);}
#define task_readArduino_Uno_Exp_AD() {task_readArduIO_AD(3);}
#define dimArduino_Uno_Exp_PWM(__PWM__,__DUTY__) \
 {dimArduIOPWM(__PWM__,(4095-__DUTY__));}
#define dimArduino_Uno_Exp_PWM1(__DUTY__) \
 {dimArduIOPWM(1,(4095-__DUTY__));}
#define dimArduino_Uno_Exp_PWM2(__DUTY__) \
 {dimArduIOPWM(2,(4095-__DUTY__));}
#define dimArduino_Uno_Exp_PWM3(__DUTY__) \
 {dimArduIOPWM(3,(4095-__DUTY__));}
// ArduIO Board Arduino Uno Expander control routine:
void task_Arduino_Uno_Exp(void);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*                    Arduino Uno Expander functions end                     */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*****************************************************************************/

#endif

/******************************************************************************
 * Additional info
 * ****************************************************************************
 * Changelog:
 * 
 *  ---> changes are documented in the file "RP6_ArduIOLib.c"
 *
 * ****************************************************************************
 */

/*****************************************************************************/
// EOF
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

Die Demo 1 besteht eigentlich aus ZWEI Testprogrammen. Wird sie so kompiliert, wie sie hier steht, erfolgt ein SCHREIB-Test (Output) auf allen Funktionen der ArduIO. Wird die Definition "WRITE_TEST" auskommentiert, erfolgt ein LESE-Test (Input).

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:

/* 
 * ****************************************************************************
 * RP6 ROBOT SYSTEM - RP6 CONTROL M32 Examples
 * ****************************************************************************
 * Example: RP6Control ArduIO
 * Author(s): Dirk
 * ****************************************************************************
 * Description:
 * In this example we show a third 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 3!\n");
	writeString_P("\nYOU MAY WATCH THE RED & GREEN MOSFET-LEDS AND/OR");
	writeString_P("\nCONNECT  A DC-MOTOR TO THE PLUG  SV_H-BRIDGES!!!\n\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 3");
	mSleep(2500);
	clearLCD();

	setLEDs(0b0000);

	// ---------------------------------------

	uint8_t duty_pct = 0;
	uint8_t cnt_sec = 0;

	startStopwatch1();

	// IMPORTANT:
	arduio_init();								// ArduIO init!!!
	enableHB1();								// Enable HB1!!!
	enableHB2();								// Enable HB2!!!

	writeString("Test -> HB1 OFF\n");
	powerHB1OFF();
	mSleep(5000);
	writeString("Test -> HB1 FWD 10%\n");
	powerHB1FWD(DUTY_PCT(10));
	mSleep(5000);
	writeString("Test -> HB1 STOP\n");
	powerHB1STOP();
	mSleep(5000);
	writeString("Test -> HB1 BWD 10%\n");
	powerHB1BWD(DUTY_PCT(10));
	mSleep(5000);
	writeString("Test -> HB1 BRK\n");
	powerHB1BRK();
	mSleep(5000);
	writeString("Test -> HB1 OFF\n");
	powerHB1OFF();
	mSleep(5000);

	writeString("Test -> HB2 OFF\n");
	powerHB2OFF();
	mSleep(5000);
	writeString("Test -> HB2 FWD 10%\n");
	powerHB2FWD(DUTY_PCT(10));
	mSleep(5000);
	writeString("Test -> HB2 STOP\n");
	powerHB2STOP();
	mSleep(5000);
	writeString("Test -> HB2 BWD 10%\n");
	powerHB2BWD(DUTY_PCT(10));
	mSleep(5000);
	writeString("Test -> HB2 BRK\n");
	powerHB2BRK();
	mSleep(5000);
	writeString("Test -> HB2 OFF\n");
	powerHB2OFF();
	mSleep(5000);

	writeString_P("\n===> PRESS BUTTON 5 TO STOP THE DEMO!!! <===\n\n");

	while(true) 
	{
		if(getStopwatch1() > 1000) // 1s
		{
			// PWM controller test:
			//   H-Bridges:
			writeString("==> HB1/2 DIM Tests: ");
			writeInteger(duty_pct, DEC);
			writeString(" % Duty Cycle");
			if (cnt_sec < 22) {					// 2 cycles FWD
				writeString(" Dir: FWD\n");
				powerHB1FWD(DUTY_PCT(duty_pct));
				powerHB2FWD(DUTY_PCT(duty_pct));
			}
			else {								// 2 cycles BWD
				writeString(" Dir: BWD\n");
				powerHB1BWD(DUTY_PCT(duty_pct));
				powerHB2BWD(DUTY_PCT(duty_pct));
			}
			cnt_sec++;
			if (cnt_sec > 43) cnt_sec = 0;
			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


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:

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*                                               ___   ___                   */
/*                 _______________________      /   \ /   \                  */
/*                 \| RP6  ROBOT SYSTEM |/     (  -  X  +  )                 */
/*                  \_-_-_-_-_-_-_-_-_-_/       \___/ \___/                  */
/*                                                ARDUINO                    */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*------------------------------ [c]2014 - Dirk -----------------------------*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~
 ~ Target:    Arduino UNO with RP6 ArduIO Board (Shield)
 ~ Library:   RP6_ArduIO Header
 ~ Version:   1.0
 ~ Author(s): Dirk
 ~
 ~ Description:
 ~ This is the RP6_ArduIO Library header file.
 ~ You have to include this file, if you want to use the library
 ~ RP6_ArduIO.cpp in your own projects.
 */
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#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 <Arduino.h>

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Define the RP6_ArduIO class and public section:
class RP6_ArduIO {

public:

RP6_ArduIO();

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// I2C PWM Controller (PCA9685):
// (A5, A4, A3 always 0, A1 always 1!)
#define I2C_ARDUIO_PWM_ADR		0x42	// A2/0 = 0/0
//#define I2C_ARDUIO_PWM_ADR		0x43	// A2/0 = 0/1
//#define I2C_ARDUIO_PWM_ADR		0x46	// A2/0 = 1/0
//#define I2C_ARDUIO_PWM_ADR		0x47	// A2/0 = 1/1
//#define I2C_ARDUIO_PWM_ADR		0x70	// 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		0x22	// A2/0 = 0/0
//#define I2C_ARDUIO_IO_1_ADR		0x23	// A2/0 = 0/1
//#define I2C_ARDUIO_IO_1_ADR		0x26	// A2/0 = 1/0
//#define I2C_ARDUIO_IO_1_ADR		0x27	// A2/0 = 1/1

//#define I2C_ARDUIO_IO_2_ADR		0x22	// A2/0 = 0/0
#define I2C_ARDUIO_IO_2_ADR		0x23	// A2/0 = 0/1
//#define I2C_ARDUIO_IO_2_ADR		0x26	// A2/0 = 1/0
//#define I2C_ARDUIO_IO_2_ADR		0x27	// A2/0 = 1/1

//#define I2C_ARDUIO_IO_3_ADR		0x22	// A2/0 = 0/0
//#define I2C_ARDUIO_IO_3_ADR		0x23	// A2/0 = 0/1
#define I2C_ARDUIO_IO_3_ADR		0x26	// A2/0 = 1/0
//#define I2C_ARDUIO_IO_3_ADR		0x27	// A2/0 = 1/1

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// I2C A/D and D/A Converter (PCF8591):
// (A1 always 1!)
#define I2C_ARDUIO_AD_1_ADR		0x4a	// A2/0 = 0/0
//#define I2C_ARDUIO_AD_1_ADR		0x4b	// A2/0 = 0/1
//#define I2C_ARDUIO_AD_1_ADR		0x4e	// A2/0 = 1/0
//#define I2C_ARDUIO_AD_1_ADR		0x4f	// A2/0 = 1/1

//#define I2C_ARDUIO_AD_2_ADR		0x4a	// A2/0 = 0/0
#define I2C_ARDUIO_AD_2_ADR		0x4b	// A2/0 = 0/1
//#define I2C_ARDUIO_AD_2_ADR		0x4e	// A2/0 = 1/0
//#define I2C_ARDUIO_AD_2_ADR		0x4f	// A2/0 = 1/1

//#define I2C_ARDUIO_AD_3_ADR		0x4a	// A2/0 = 0/0
//#define I2C_ARDUIO_AD_3_ADR		0x4b	// A2/0 = 0/1
#define I2C_ARDUIO_AD_3_ADR		0x4e	// A2/0 = 1/0
//#define I2C_ARDUIO_AD_3_ADR		0x4f	// 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

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Arduino Uno Expander definitions:
// ATTENTION: Using this library you MAY NOT connect a RP6 System Board (RP6
//            Base, CONTROL M32, M256 WiFi) to the RP6 ArduIO Board using the
//            RP6 XBUS plug on the ArduIO Board, if the RP6 System 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

// 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

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// ArduIO Status:

#define DISABLE_ON_SHUTDOWN		// Disable access to PPWM, PWM, Out
					// & DAC ports in SHUTDOWN mode
					// (default)!

// The ArduIO status bits with access settings & UB voltage low flag:
typedef union status_t {
  byte bits;
    struct {
      unsigned ubatLow       :1;	// UB voltage low
      unsigned hb1Enable     :1;	// H-Bridge 1 (HB1) enable
      unsigned hb2Enable     :1;	// H-Bridge 2 (HB2) enable
      unsigned ppwm_g1Enable :1;	// Power PWM group 1 (PPWM1..4) enable
      unsigned ppwm_g2Enable :1;	// Power PWM group 2 (PPWM5..8) enable
      unsigned pwmsEnable    :1;	// Free PWMs (PWM1..4) enable
      unsigned outsEnable    :1;	// IO_1..3 IOs enable as outputs
      unsigned dasEnable     :1;	// ADDA_1..3 DACs enable
    };
};

status_t status;  // ArduIO status bits (read only)

// Functions:
void enableHB(byte);
void disableHB(byte);
void enablePPWM_G(byte);
void disablePPWM_G(byte);
void enablePWMs(void);
void disablePWMs(void);
void enableOuts(void);
void disableOuts(void);
void enableDAs(void);
void disableDAs(void);
#define setArduIODefaultStatus() {enablePPWM_G(1);enablePPWM_G(2); \
 enablePWMs();enableOuts();enableDAs();}
#define setArduIOShutdownStatus() {disableHB(1);disableHB(2); \
 disablePPWM_G(1);disablePPWM_G(2);disablePWMs();disableOuts();disableDAs();}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// I2C PWM Controller (PCA9685):

// Registers:
#define PCA9685_MODE1			0
#define PCA9685_MODE2			1
#define PCA9685_SUBADR1			2
#define PCA9685_SUBADR2			3
#define PCA9685_SUBADR3			4
#define PCA9685_ALLCALLADR		5
#define PCA9685_LED0_ON_L		6
#define PCA9685_LED0_ON_H		7
#define PCA9685_LED0_OFF_L		8
#define PCA9685_LED0_OFF_H		9
#define PCA9685_LED1_ON_L		10
#define PCA9685_LED1_ON_H		11
#define PCA9685_LED1_OFF_L		12
#define PCA9685_LED1_OFF_H		13
#define PCA9685_LED2_ON_L		14
#define PCA9685_LED2_ON_H		15
#define PCA9685_LED2_OFF_L		16
#define PCA9685_LED2_OFF_H		17
#define PCA9685_LED3_ON_L		18
#define PCA9685_LED3_ON_H		19
#define PCA9685_LED3_OFF_L		20
#define PCA9685_LED3_OFF_H		21
#define PCA9685_LED4_ON_L		22
#define PCA9685_LED4_ON_H		23
#define PCA9685_LED4_OFF_L		24
#define PCA9685_LED4_OFF_H		25
#define PCA9685_LED5_ON_L		26
#define PCA9685_LED5_ON_H		27
#define PCA9685_LED5_OFF_L		28
#define PCA9685_LED5_OFF_H		29
#define PCA9685_LED6_ON_L		30
#define PCA9685_LED6_ON_H		31
#define PCA9685_LED6_OFF_L		32
#define PCA9685_LED6_OFF_H		33
#define PCA9685_LED7_ON_L		34
#define PCA9685_LED7_ON_H		35
#define PCA9685_LED7_OFF_L		36
#define PCA9685_LED7_OFF_H		37
#define PCA9685_LED8_ON_L		38
#define PCA9685_LED8_ON_H		39
#define PCA9685_LED8_OFF_L		40
#define PCA9685_LED8_OFF_H		41
#define PCA9685_LED9_ON_L		42
#define PCA9685_LED9_ON_H		43
#define PCA9685_LED9_OFF_L		44
#define PCA9685_LED9_OFF_H		45
#define PCA9685_LED10_ON_L		46
#define PCA9685_LED10_ON_H		47
#define PCA9685_LED10_OFF_L		48
#define PCA9685_LED10_OFF_H		49
#define PCA9685_LED11_ON_L		50
#define PCA9685_LED11_ON_H		51
#define PCA9685_LED11_OFF_L		52
#define PCA9685_LED11_OFF_H		53
#define PCA9685_LED12_ON_L		54
#define PCA9685_LED12_ON_H		55
#define PCA9685_LED12_OFF_L		56
#define PCA9685_LED12_OFF_H		57
#define PCA9685_LED13_ON_L		58
#define PCA9685_LED13_ON_H		59
#define PCA9685_LED13_OFF_L		60
#define PCA9685_LED13_OFF_H		61
#define PCA9685_LED14_ON_L		62
#define PCA9685_LED14_ON_H		63
#define PCA9685_LED14_OFF_L		64
#define PCA9685_LED14_OFF_H		65
#define PCA9685_LED15_ON_L		66
#define PCA9685_LED15_ON_H		67
#define PCA9685_LED15_OFF_L		68
#define PCA9685_LED15_OFF_H		69
#define PCA9685_ALL_LED_ON_L		250
#define PCA9685_ALL_LED_ON_H		251
#define PCA9685_ALL_LED_OFF_L		252
#define PCA9685_ALL_LED_OFF_H		253
#define PCA9685_PRE_SCALE		254
#define PCA9685_TESTMODE		255

// Mode1 register bitmasks:
#define PCA9685_MODE1_DEFAULT		17
#define PCA9685_MODE1_ALLCALL		1
#define PCA9685_MODE1_SUB3		2
#define PCA9685_MODE1_SUB2		4
#define PCA9685_MODE1_SUB1		8
#define PCA9685_MODE1_SLEEP		16
#define PCA9685_MODE1_AI		32
#define PCA9685_MODE1_EXTCLK		64
#define PCA9685_MODE1_RESTART		128

// Mode2 register bitmasks:
#define PCA9685_MODE2_DEFAULT		4		// Totem poles (default)
#define PCA9685_MODE2_ARDUIO		16		// Inverted open-drains
#define PCA9685_MODE2_OUTDRV		4
#define PCA9685_MODE2_OCH		8
#define PCA9685_MODE2_INVRT		16

#define F_PCA9685			25000000.0	// Int. Clock: 25 MHz

void PCA9685_init(unsigned int);
void PCA9685_set(byte, unsigned int);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// I2C I/O Expander (PCA9535):

// Registers:
#define PCA9535_INPUT_P0		0
#define PCA9535_INPUT_P1		1
#define PCA9535_OUTPUT_P0		2
#define PCA9535_OUTPUT_P1		3
#define PCA9535_POL_INV_P0		4
#define PCA9535_POL_INV_P1		5
#define PCA9535_CONFIG_P0		6
#define PCA9535_CONFIG_P1		7

// I2C I/O Expander 1 5V (IC8: PCA9535):
#define IO_1				1
typedef union {
  unsigned int port;
    struct {
      unsigned P00:1;				// P00
      unsigned P01:1;				// P01
      unsigned P02:1;				// P02
      unsigned P03:1;				// P03
      unsigned P04:1;				// P04
      unsigned P05:1;				// P05
      unsigned P06:1;				// P06
      unsigned P07:1;				// P07
      unsigned P10:1;				// P10
      unsigned P11:1;				// P11
      unsigned P12:1;				// P12
      unsigned P13:1;				// P13
      unsigned P14:1;				// P14
      unsigned P15:1;				// P15
      unsigned P16:1;				// P16
      unsigned P17:1;				// P17
    };
    struct {
      unsigned GP100:1;				// IO_1: P00
      unsigned GP101:1;				// IO_1: P01
      unsigned GP102:1;				// IO_1: P02
      unsigned GP103:1;				// IO_1: P03
      unsigned GP104:1;				// IO_1: P04
      unsigned GP105:1;				// IO_1: P05
      unsigned GP106:1;				// IO_1: P06
      unsigned GP107:1;				// IO_1: P07
      unsigned GP110:1;				// IO_1: P10
      unsigned GP111:1;				// IO_1: P11
      unsigned GP112:1;				// IO_1: P12
      unsigned GP113:1;				// IO_1: P13
      unsigned GP114:1;				// IO_1: P14
      unsigned GP115:1;				// IO_1: P15
      unsigned GP116:1;				// IO_1: P16
      unsigned GP117:1;				// IO_1: P17
    };
} ioexp_1_t;

ioexp_1_t io1config;
ioexp_1_t io1invrt;
ioexp_1_t io1ins;
ioexp_1_t io1outs;

// I2C I/O Expander 2 5V (IC13: PCA9535):
#define IO_2				2
typedef union {
  unsigned int port;
    struct {
      unsigned P00:1;				// P00
      unsigned P01:1;				// P01
      unsigned P02:1;				// P02
      unsigned P03:1;				// P03
      unsigned P04:1;				// P04
      unsigned P05:1;				// P05
      unsigned P06:1;				// P06
      unsigned P07:1;				// P07
      unsigned P10:1;				// P10
      unsigned P11:1;				// P11
      unsigned P12:1;				// P12
      unsigned P13:1;				// P13
      unsigned P14:1;				// P14
      unsigned P15:1;				// P15
      unsigned P16:1;				// P16
      unsigned P17:1;				// P17
    };
    struct {
      unsigned GP200:1;				// IO_2: P00
      unsigned GP201:1;				// IO_2: P01
      unsigned GP202:1;				// IO_2: P02
      unsigned GP203:1;				// IO_2: P03
      unsigned GP204:1;				// IO_2: P04
      unsigned GP205:1;				// IO_2: P05
      unsigned GP206:1;				// IO_2: P06
      unsigned GP207:1;				// IO_2: P07
      unsigned GP210:1;				// IO_2: P10
      unsigned GP211:1;				// IO_2: P11
      unsigned GP212:1;				// IO_2: P12
      unsigned GP213:1;				// IO_2: P13
      unsigned GP214:1;				// IO_2: P14
      unsigned GP215:1;				// IO_2: P15
      unsigned GP216:1;				// IO_2: P16
      unsigned GP217:1;				// IO_2: P17
    };
    struct {
      unsigned ARD_D0:1;			// ARD: D0
      unsigned ARD_D1:1;			// ARD: D1
      unsigned ARD_D2:1;			// ARD: D2
      unsigned ARD_D3:1;			// ARD: D3
      unsigned ARD_D4:1;			// ARD: D4
      unsigned ARD_D5:1;			// ARD: D5
      unsigned ARD_D6:1;			// ARD: D6
      unsigned ARD_D7:1;			// ARD: D7
      unsigned ARD_D13:1;			// ARD: D13
      unsigned ARD_D12:1;			// ARD: D12
      unsigned ARD_D11:1;			// ARD: D11
      unsigned ARD_D10:1;			// ARD: D10
      unsigned ARD_D9:1;			// ARD: D9
      unsigned ARD_D8:1;			// ARD: D8
      unsigned unusedGP216:1;			// unused
      unsigned unusedGP217:1;			// unused
   };
} ioexp_2_t;

ioexp_2_t io2config;
ioexp_2_t io2invrt;
ioexp_2_t io2ins;
ioexp_2_t io2outs;

// I2C I/O Expander 3 3V3 (IC12: PCA9535):
#define IO_3				3
typedef union {
  unsigned int port;
    struct {
      unsigned P00:1;				// P00
      unsigned P01:1;				// P01
      unsigned P02:1;				// P02
      unsigned P03:1;				// P03
      unsigned P04:1;				// P04
      unsigned P05:1;				// P05
      unsigned P06:1;				// P06
      unsigned P07:1;				// P07
      unsigned P10:1;				// P10
      unsigned P11:1;				// P11
      unsigned P12:1;				// P12
      unsigned P13:1;				// P13
      unsigned P14:1;				// P14
      unsigned P15:1;				// P15
      unsigned P16:1;				// P16
      unsigned P17:1;				// P17
    };
    struct {
      unsigned GP300:1;				// IO_3: P00
      unsigned GP301:1;				// IO_3: P01
      unsigned GP302:1;				// IO_3: P02
      unsigned GP303:1;				// IO_3: P03
      unsigned GP304:1;				// IO_3: P04
      unsigned GP305:1;				// IO_3: P05
      unsigned GP306:1;				// IO_3: P06
      unsigned GP307:1;				// IO_3: P07
      unsigned GP310:1;				// IO_3: P10
      unsigned GP311:1;				// IO_3: P11
      unsigned GP312:1;				// IO_3: P12
      unsigned GP313:1;				// IO_3: P13
      unsigned GP314:1;				// IO_3: P14
      unsigned GP315:1;				// IO_3: P15
      unsigned GP316:1;				// IO_3: P16
      unsigned GP317:1;				// IO_3: P17
    };
} ioexp_3_t;

ioexp_3_t io3config;
ioexp_3_t io3invrt;
ioexp_3_t io3ins;
ioexp_3_t io3outs;

// I2C I/O Expander (PCA9535) general functions:
void config_IO(byte, unsigned int);
void update_IO(byte);
void set_IO(byte, unsigned int);
void invert_IO(byte, unsigned int);
void read_IO(byte);
#define readAllArduIO_IOs() {read_IO(1);read_IO(2);read_IO(3);}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// I2C A/D and D/A Converter (PCF8591):

#define READ_ADCUB	// If defined: Function read_AD(1) will also
			//  (default)  read the UB voltage ADC value (adcub) and
			//             will update the UB voltage low condition
			//             flag (status.ubatLow)!
			// If NOT defined: The UB voltage ADC value can be found
			//                 in the variable ad1ins.ArduIO_UB after
			//                 execution of read_AD(1)!
			// READ_ADCUB should NOT be defined, if jumper JP_AD-UB
			// on the ArduIO Board is OPEN!

// Control Byte bitmasks:
#define PCF8591_CONTROL_DEFAULT		0
#define PCF8591_CONTROL_ARDUIO		0b01000100	// Auto-increment & DAC

#define PCF8591_CONTROL_AUTO_INC	4		// Auto-increment
#define PCF8591_CONTROL_DAC_ENABLE	64		// DAC enable

// I2C A/D and D/A Converter 1 (IC11: PCF8591):
#define ADDA_1				1
typedef union {
  struct {
    byte AIN0;					// AIN0
    byte AIN1;					// AIN1
    byte AIN2;					// AIN2
    byte AIN3;					// AIN3
  };
  struct {
    byte AD10;					// ADDA_1: AIN0
    byte AD11;					// ADDA_1: AIN1
    byte AD12;					// ADDA_1: AIN2
    byte AD13;					// ADDA_1: AIN3
  };
  struct {
    byte unusedAD10;				// unused
    byte unusedAD11;				// unused
    byte unusedAD12;				// unused
    byte ArduIO_UB;				// ArduIO: UB
  };
} addaexp_1_t;

addaexp_1_t ad1ins;

// I2C A/D and D/A Converter 2 (IC10: PCF8591):
#define ADDA_2				2
typedef union {
  struct {
    byte AIN0;					// AIN0
    byte AIN1;					// AIN1
    byte AIN2;					// AIN2
    byte AIN3;					// AIN3
  };
  struct {
    byte AD20;					// ADDA_2: AIN0
    byte AD21;					// ADDA_2: AIN1
    byte AD22;					// ADDA_2: AIN2
    byte AD23;					// ADDA_2: AIN3
  };
} addaexp_2_t;

addaexp_2_t ad2ins;

// I2C A/D and D/A Converter 3 (IC9: PCF8591):
#define ADDA_3				3
typedef union {
  struct {
    byte AIN0;					// AIN0
    byte AIN1;					// AIN1
    byte AIN2;					// AIN2
    byte AIN3;					// AIN3
  };
  struct {
    byte AD30;					// ADDA_3: AIN0
    byte AD31;					// ADDA_3: AIN1
    byte AD32;					// ADDA_3: AIN2
    byte AD33;					// ADDA_3: AIN3
  };
  struct {
    byte ARD_A0;				// ARD: A0
    byte ARD_A1;				// ARD: A1
    byte ARD_A2;				// ARD: A2
    byte ARD_A3;				// ARD: A3
  };
} addaexp_3_t;

addaexp_3_t ad3ins;

// I2C A/D and D/A Converter (PCF8591) general functions:
#define UCV_AD(__AD__) (unsigned int)(__AD__*500.0f/255.0f)

void read_AD(byte);
#define readAllArduIO_ADs() {read_AD(1);read_AD(2);read_AD(3);}

#define AOUT_CV(__CV__) (byte)(__CV__*0.51f)

byte da1aout;
byte da2aout;
byte da3aout;

void write_DA(byte, byte);
void disable_DA(byte);
#define disableAllArduIO_DAs() {disable_DA(1);disable_DA(2);disable_DA(3);}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// UB Voltage Sensor:

byte adcub;
double ubv;

byte getUbSensor(void);
double calculateUb(void);
double measureUb(void);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// LEDs:

// ------------------------------------------------------------------
// Duty cycle constants:
#define DUTY_0				0	// 0%
#define DUTY_10				409	// 10%
#define DUTY_25				1023	// 25%
#define DUTY_50				2047	// 50%
#define DUTY_75				3071	// 75%
#define DUTY_90				3685	// 90%
#define DUTY_100			4095	// 100%
// Relative duty cycle [__PCT__ = 0..100%] macro:
#define DUTY_PCT(__PCT__) (unsigned int)((unsigned long)__PCT__*4095/100)
// ------------------------------------------------------------------

void setLEDs(byte);

void dimLED(byte, unsigned int);
void setLED1(byte);
void setLED2(byte);
void setLED3(byte);
void setLED4(byte);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// PWM Ports:

void setPWMs(byte);

void dimPWM(byte, unsigned int);
void setPWM1(byte);
void setPWM2(byte);
void setPWM3(byte);
void setPWM4(byte);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Power PWM Ports & H-Bridges:

// Power PWM Ports:
void setPowerPWMMode(void);
void setPowerPWMs(byte);

void dimPowerPWM(byte, unsigned int);
void setPowerPWM1(byte);
void setPowerPWM2(byte);
void setPowerPWM3(byte);
void setPowerPWM4(byte);
void setPowerPWM5(byte);
void setPowerPWM6(byte);
void setPowerPWM7(byte);
void setPowerPWM8(byte);

// H-Bridges:

// ------------------------------------------------------------
// Direction/command:
#define FWD			0		// Forwards
#define BWD			1		// Backwards
#define BRK			4		// Speed break
#define OFF			5		// Power OFF
// ------------------------------------------------------------

void adjustPowerHB(byte hb, byte dir, unsigned int duty);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// ArduIO Board system control routine:

void readSystem(void);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// ArduIO Board initialisation and shutdown:

void init(void);
void shutdown(void);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Arduino Uno Expander functions:

void updateArduino_Uno_Exp_IO(void);
void setArduino_Uno_Exp_IO(unsigned int);
// ArduIO Board Arduino Uno Expander control routine:
void readArduino_Uno_Exp(void);

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Class private section and end:

private:

status_t RP6ArduIOstatus;	// ArduIO status bits (lib internal)

};

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#endif

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~ Additional info
 ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~ Changelog:
 ~
 ~  ---> changes are documented in the file "RP6_ArduIO.cpp"
 ~
 ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
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


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 13:07, 23. Nov 2014 (CET)


LiFePO4 Speicher Test