Hi guys,
I'm very new to this stuff and am trying to upload code to my Nano 3.0 but its coming up with errors.
I'm using the Arduino 3.0 w/ATmega328 to use a set of CST/Five Star Simulations sim racing pedals to work with the Fanatec CSW wheel base on the PS3, I have them working fine individually on the PC but want to make them work with the PS3 as well.
A guy on the GTPlanet forums did all the schematic and programming and uploaded it, I've followed his schematic and downloaded the Arduino 1.0.5-r2 software, created a new sketch, opened my file (pedals.ino), set the board to arduino nano w/ATmega328 and set com port to #3.
When I verify or try to upload it comes up with an error 'Adafruit_MCP4725' does not name a type
I've attached a copy of the code below, error message and INO file and schematic in a zip file to help demonstrate what I'm trying to do.
In the code below there was //comments everywhere, I had to delete them all as the post can only have 9500 characters, all the comments will be in the pedals.ino file if you need clarification on anything.
Thanks in advance for your help
//#define _DEBUG_ALL_
//#define _DEBUG_EEPROM_
#define USE_EEPROM
#define USE_DAC
#ifdef _DEBUG_EEPROM_
#define _EEPROMEX_DEBUG
#endif
#ifdef USE_DAC
#include <Wire.h>
#include <Adafruit_MCP4725.h>
#endif
#include <Bounce2.h>
#ifdef USE_EEPROM
#include <EEPROMex.h>
#endif
#define SERIAL_SPEED 9600
// Analog Pin definitions
#define THROTTLE_IN 0
#define BRAKE_IN 1
#define CLUTCH_IN 2
// Digital Pin definitions
#define CALIBRATE_PIN 2
#define THROTTLE_INVERT_PIN 10
#define BRAKE_INVERT_PIN 9
#define SPARE_DIP_3 8
#define GREEN_LED_PIN 11
#define RED_LED_PIN 12
int throttleStart;
int throttleEnd;
int brakeStart;
int brakeEnd;
int configAddress = 0;
struct conf
{
int throttleMin;
int throttleMax;
int brakeMin;
int brakeMax;
} config = { 0 , 1023 , 0 , 1023 }; // Default to full 10 bit ADC
#ifdef USE_DAC
Adafruit_MCP4725 throttleDAC; // 12 Bit DAC for the throttle output to Fanatec CSW
Adafruit_MCP4725 brakeDAC; // 12 Bit DAC for the clutch output to Fanatec CSW
#endif
#define BLINK 0x2
#define BLINK_INTERVAL 250
#define GREEN_LED 0
#define RED_LED 1
struct
{
boolean blink;
int pin;
int state;
unsigned long previousMillis;
} ledState[2] = { { false , GREEN_LED_PIN , LOW , 0L } , { false , RED_LED_PIN , LOW , 0L } };
#define DEBOUNCE_TIME 500
Bounce calibrateButton;
int calibrateState = 0;
void setup()
{
#ifdef _DEBUG_ALL_
// Initialise Serial connections
Serial.begin( SERIAL_SPEED );
Serial.println( "setup() Started" );
#endif
// Read config from EEPROM
readEEPROM();
pinMode( CALIBRATE_PIN , INPUT_PULLUP );
pinMode( THROTTLE_INVERT_PIN , INPUT_PULLUP );
pinMode( BRAKE_INVERT_PIN , INPUT_PULLUP );
calibrateButton.attach( CALIBRATE_PIN );
calibrateButton.interval( DEBOUNCE_TIME );
pinMode( ledState[RED_LED].pin , OUTPUT );
pinMode( ledState[GREEN_LED].pin , OUTPUT );
setLED( RED_LED , LOW );
setLED( GREEN_LED , LOW );
analogReference( DEFAULT );
#ifdef USE_DAC
throttleDAC.begin( 0x62 );
brakeDAC.begin( 0x63 );
#endif
if ( digitalRead( THROTTLE_INVERT_PIN ) == LOW )
{ throttleStart = 4095; throttleEnd = 0; }
else
{ throttleStart = 0; throttleEnd = 4095; }
if ( digitalRead( BRAKE_INVERT_PIN ) == LOW )
{ brakeStart = 4095; brakeEnd = 0; }
else
{ brakeStart = 0; brakeEnd = 4095; }
#ifdef _DEBUG_ALL_
Serial.println( "setup() Finished" );
#endif
}
void loop()
{
unsigned int t;
unsigned int b;
if ( checkCalibrationState() != 0 ) return;
t = analogRead( THROTTLE_IN );
b = analogRead( BRAKE_IN );
#ifdef _DEBUG_ALL_
Serial.print( "TMin:" ); Serial.print( config.throttleMin );
Serial.print( " TMax:" ); Serial.print( config.throttleMax );
Serial.print( " BMin:" ); Serial.print( config.brakeMin );
Serial.print( " BMax:" ); Serial.print( config.brakeMax );
Serial.print( " TStart:" ); Serial.print( throttleStart );
Serial.print( " TEnd:" ); Serial.print( throttleEnd );
Serial.print( " BStart:" ); Serial.print( brakeStart );
Serial.print( " BEnd:" ); Serial.print( brakeEnd );
Serial.print( " TOld:" ); Serial.print( t );
Serial.print( " BOld:" ); Serial.print( b );
#endif
t = constrain( t , config.throttleMin , config.throttleMax );
t = map( t , config.throttleMin , config.throttleMax , throttleStart , throttleEnd );
#ifdef USE_DAC
throttleDAC.setVoltage( t , false );
#endif
b = constrain( b , config.brakeMin , config.brakeMax );
b = map( b , config.brakeMin , config.brakeMax , brakeStart , brakeEnd );
#ifdef USE_DAC
brakeDAC.setVoltage( b , false );
#endif
#ifdef _DEBUG_ALL_
Serial.print( " TNew:" ); Serial.print( t );
Serial.print( " BNew:" ); Serial.println( b );
#endif
}
int checkCalibrationState()
{
blinkLED( GREEN_LED ); blinkLED( RED_LED );
boolean stateChanged = calibrateButton.update();
int state = calibrateButton.read();
if ( stateChanged && state == LOW )
{
#ifdef _DEBUG_ALL_
Serial.print( "Calibration Change detected. Before:" );
Serial.print( calibrateState );
Serial.print( " After:" );
#endif
calibrateState = (calibrateState + 1)%5;
switch( calibrateState )
{
case 1: setLED( GREEN_LED , HIGH ); break;
case 2: config.throttleMin = analogRead( THROTTLE_IN ); setLED( GREEN_LED , BLINK ); break;
case 3: config.throttleMax = analogRead( THROTTLE_IN ); setLED( GREEN_LED , LOW ); setLED( RED_LED , HIGH ); break;
case 4: config.brakeMin = analogRead( BRAKE_IN ); setLED( RED_LED , BLINK ); break;
case 0: config.brakeMax = analogRead( BRAKE_IN ); writeEEPROM(); setLED( RED_LED , LOW ); break; // Be explicit and use 0, don't burn out eeprom if error
default: break;
}
#ifdef _DEBUG_ALL_
Serial.println( calibrateState );
#endif
}
return calibrateState;
}
void setLED( int led , int state )
{
if ( state == BLINK )
{
ledState[led].blink = true;
ledState[led].previousMillis = millis();
state = LOW;
}
else ledState[led].blink = false;
ledState[led].state = state;
digitalWrite( ledState[led].pin , state );
}
void blinkLED( int led )
{
if ( !ledState[led].blink ) return;
unsigned long currentMillis = millis();
if ( ( currentMillis - ledState[led].previousMillis) > BLINK_INTERVAL )
{
ledState[led].previousMillis = currentMillis;
if ( ledState[led].state == LOW )
setLED( led , HIGH );
else
setLED( led , LOW );
ledState[led].blink = true;
}
}
// EEPROM Functions
void readEEPROM()
{
#ifdef USE_EEPROM
EEPROM.setMemPool( 0 , EEPROMSizeNano );
EEPROM.setMaxAllowedWrites( 100 );
configAddress = EEPROM.getAddress( sizeof( struct conf ) );
EEPROM.readBlock<struct conf>( configAddress, config );
#endif
#ifdef _DEBUG_EEPROM_
Serial.print( "Address:" ); Serial.println( configAddress );
Serial.print( "sizeof(struct config):" ); Serial.println( sizeof( struct conf ) );
Serial.print( "throttleMin:" ); Serial.print( config.throttleMin );
Serial.print( " throttleMax:" ); Serial.println( config.throttleMax );
Serial.print( "brakeMin:" ); Serial.print( config.brakeMin );
Serial.print( " brakeMax:" ); Serial.println( config.brakeMax );
#endif
}
void writeEEPROM()
{
#ifdef USE_EEPROM
int i;
if ( config.throttleMax < config.throttleMin ) { i = config.throttleMax; config.throttleMax = config.throttleMin; config.throttleMin = i; }
if ( config.brakeMax < config.brakeMin ) { i = config.brakeMax; config.brakeMax = config.brakeMin; config.brakeMin = i; }
EEPROM.writeBlock<struct conf>( configAddress , config );
#endif
}
Fanatec_CST_Diagrams_And_Code (2).zip (2.56 MB)
