Problem with Pro Version and loading code

This forum is for all topics related to Simulator for Arduino v0.98. Please include sample code where possible.

Moderator: Adrian

interspec
Posts: 1
Joined: Fri Jan 04, 2013 6:14 pm

Problem with Pro Version and loading code

Postby interspec » Fri Jan 04, 2013 6:21 pm

//*********************************************************************
//
// INCLUDES
//
//*********************************************************************

#include <SoftwareSerial.h>

#include "ROV_Control.h"

#include "Serial.h"

#include "OneWire.h"

#include "TDCmp.h"

#include "Servo.h"

#include "Leak.h"

#include "Motor.h"

#include "ExtraSensors.h"

#include "Packet.h"

// DS18B20 Temperature sensors
// Use proprietary OneWire (tm) interface.
#include <OneWire.h>
// Definition of interrupt names
#include < avr/io.h >
// ISR interrupt service routine
#include < avr/interrupt.h >


//*********************************************************************
//
// SETUP
//
//*********************************************************************

void setup() {

TOP_SIDE_SERIAL.begin(115200);

pinMode(13,OUTPUT);
digitalWrite(13,LOW);
#ifdef LEAKS
pinMode(MCU_LEAK_SENSOR_DIGITAL_PIN, INPUT);
pinMode(MOTOR_LEAK_SENSOR_DIGITAL_PIN, INPUT);
//enableInterrupts();
#endif

pinMode(LIGHT_TRANSISTOR_CONTROL_PIN,OUTPUT);
digitalWrite(LIGHT_TRANSISTOR_CONTROL_PIN,LOW);
//setupSerial();

#ifdef TMPS
setupOneWire(ONE_WIRE_SETUP_TIMEOUT_MS);
#endif

#ifdef TDCMP
//validateTDCMP(TDCMP_SETUP_TIMEOUT_MS);
#endif

#ifdef SERVOS
setupServos();
#endif

#ifdef MOTORS
setupMotors();
#endif

#ifdef EXTRAS
setupExtraSensors();
#endif
}

boolean enableInterrupts(void) {

attachInterrupt(0, handleMcuLeak, RISING);
attachInterrupt(1, handleMotorLeak, RISING);

return true;
}


boolean setupServos(void) {

//LightServo.attach(LIGHT_SERVO_CONTROL_PIN);

//TiltServo.attach(TILT_SERVO_CONTROL_PIN);
}

boolean setupSerial(void) {

TOP_SIDE_SERIAL.begin(115200);
TOP_SIDE_SERIAL.flush();
//TDCMP_SERIAL.begin(115200);
//TDCMP_SERIAL.flush();

return true;
}

boolean setupOneWire(millisec_t timeOut) {

char message[100];
boolean failed = false;
boolean complete = false;
millisec_t limit = millis() + timeOut;
uint8_t state = 0;

while (millis() < limit)
{
switch (state) {
case 0:
failed = !setupOneWireAddresses();
break;
case 1:
failed = !setupOneWireTypes();
break;
default:
complete = true;
break;
}

if (complete) {
break;
}

if (!failed) {
state++;
}
}

return failed;
}

//*********************************************************************
//
// OneWire
//
//*********************************************************************

char* identifySensor(DS18xxx_t *sensor, DS18xxx_op op) {

static byte externalAddr[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
static byte mcuAddr[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
//static byte motorsAddr[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
char* ret = (char*)DS18xxx_UNKNOWN;

if (op == DS18xxx_WRITE_EXTERNAL) {

copyAddr(sensor,externalAddr);

} else if (op == DS18xxx_WRITE_MCU) {

copyAddr(sensor,mcuAddr);

/*} else if (op == DS18xxx_WRITE_MOTORS) {

copyAddr(sensor,motorsAddr);
*/
} else {

//READ
if (compareAddr(sensor,externalAddr) == true) {

ret = (char*)DS18xxx_EXTERNAL;

} else if (compareAddr(sensor,mcuAddr) == true) {

ret = (char*)DS18xxx_MCU;

} /*else if (compareAddr(sensor,motorsAddr) == true) {

ret = (char*)DS18xxx_MOTORS;

}*/
}

return ret;
}

boolean compareAddr(DS18xxx_t *sensor, byte* buffer) {

boolean ret = true;
int i=0;

for (i=0; i<8; i++) {
if (sensor->addr[i] != buffer[i]) {
ret = false;
break;
}
}

return ret;
}

boolean copyAddr(DS18xxx_t *sensor, byte* buffer) {
int i=0;

for (i=0; i<8; i++) {
buffer[i] = sensor->addr[i];
}

return true;
}

uint8_t getTemperature(DS18xxx_t *sensor, char* buffer) {

byte i;
byte data[12];
byte present = 0;
float celsius = 0;
char* id = (char*)DS18xxx_UNKNOWN;

sensor->controlLine->reset();
sensor->controlLine->select(sensor->addr);
sensor->controlLine->write(0x44,1); // start conversion, with parasite power on at the end

delay(ONE_WIRE_READ_TEMP_DELAY); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = sensor->controlLine->reset();
sensor->controlLine->select(sensor->addr);
sensor->controlLine->write(0xBE); // Read Scratchpad

id = identifySensor(sensor,DS18xxx_READ);

#ifdef VERBOSITY_2
DEBUG_PRINT(id);
#endif

#ifdef VERBOSITY_0
DEBUG_PRINT(" Data = ");
DEBUG_PRINT_T(present,HEX);
DEBUG_PRINT(" ");
#endif

for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = sensor->controlLine->read();
#ifdef VERBOSITY_0
DEBUG_PRINT_T(data[i], HEX);
DEBUG_PRINT(" ");
#endif
}
#ifdef VERBOSITY_0
DEBUG_PRINT(" CRC=");
DEBUG_PRINT_T(OneWire::crc8(data, 8), HEX);
DEBUG_PRINTLN();
#endif

// convert the data to actual temperature

int16_t raw = (data[1] << 8) | data[0];

if (sensor->type == DS18S20) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// count remain gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg ==


a sample of the code im trying to test it wont run in your software can you help ?

Simulator_admin
Site Admin
Posts: 239
Joined: Thu Feb 02, 2012 6:07 pm

Re: Problem with Pro Version and loading code

Postby Simulator_admin » Fri Jan 04, 2013 6:57 pm

The Simulator has been designed to have 6 files open at one time (EDIT: now upgraded to 20 so that libraries will be able to be used). Looking at the sketch, there are many .h files included and some .h files will also open the .cpp files. We can change this but this change is not easy.


Return to “Version 0.98”

Who is online

Users browsing this forum: No registered users and 1 guest