I am trying to use an example and trying to add to it for a project I am working on and It involves the ATmega8 and OBD2 library with a MCP2515 module. I am getting an error that says
Arduino\libraries\OBD2\src\OBD2.cpp: In member function 'String OBD2Class::pidUnits(uint8_t)':
Arduino\libraries\OBD2\src\OBD2.cpp:432:26: error: invalid conversion from 'void*' to 'const char*' [-fpermissive]
const char* pgmUnits = pgm_read_ptr(&PID_UNIT_MAPPER[pid]);
^
exit status 1
Compilation error: exit status 1
I was wondering if someone can help me figure out what the error means and what the solution.
I attached link of the code which i use in this project.
c:/users/dell/appdata/local/arduino15/packages/dxcore/tools/avr-gcc/7.3.0-atmel3.6.1-azduino4b/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: C:\Users\DELL\AppData\Local\Temp\arduino-sketch-BC6274E536839CA9049DFA7EA277D68E/OBD2_02_KeyStats.ino.elf section `.text' will not fit in region `text'
c:/users/dell/appdata/local/arduino15/packages/dxcore/tools/avr-gcc/7.3.0-atmel3.6.1-azduino4b/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld.exe: region `text' overflowed by 8342 bytes
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
but for your reference i again provide full code using code tags
// Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <CAN.h> // the OBD2 library depends on the CAN library
#include <OBD2.h>
// array of PID's to print values of
const int PIDS[] = {
CALCULATED_ENGINE_LOAD,
ENGINE_COOLANT_TEMPERATURE,
ENGINE_RPM,
VEHICLE_SPEED,
AIR_INTAKE_TEMPERATURE,
MAF_AIR_FLOW_RATE,
THROTTLE_POSITION,
RUN_TIME_SINCE_ENGINE_START,
FUEL_TANK_LEVEL_INPUT,
ABSOLULTE_BAROMETRIC_PRESSURE,
ABSOLUTE_LOAD_VALUE,
RELATIVE_THROTTLE_POSITION
};
const int NUM_PIDS = sizeof(PIDS) / sizeof(PIDS[0]);
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println(F("OBD2 Key Stats"));
while (true) {
Serial.print(F("Attempting to connect to OBD2 CAN bus ... "));
if (!OBD2.begin()) {
Serial.println(F("failed!"));
delay(1000);
} else {
Serial.println(F("success"));
break;
}
}
Serial.println();
}
void loop() {
// loop through all the PID's in the array
//
for (int i = 0; i < NUM_PIDS; i++) {
int pid = PIDS[i];
printPID(pid);
}
Serial.println();
delay(1000);
}
void printPID(int pid) {
// print PID name
Serial.print(OBD2.pidName(pid));
Serial.print(F(" = "));
// read the PID value
float pidValue = OBD2.pidRead(pid);
if (isnan(pidValue)) {
Serial.print("error");
} else {
// print value with units
Serial.print(pidValue);
Serial.print(F(" "));
Serial.print(OBD2.pidUnits(pid));
}
Serial.println();
}
Posting a link is different to posting it in code tags here.
There is nothing that could be removed from your sketch, or shrunk
(to make a real difference, some bytes could be spared),
it uses more than double the available space, so you will need a bigger MCU.
@Whandall i change the code and it does not show any error. but it does not work. It work fine in ATmega328.
// Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
//
// This examples queries the engine RPM (OBD-II PID 0x0c) once a seconds and
// prints the value to the Serial monitor
//
#include <CAN.h>
// Most cars support 11-bit adddress, others (like Honda),
// require 29-bit (extended) addressing, set the next line
// to true to use extended addressing
const bool useStandardAddressing = false;
void setup() {
Serial.begin(9600);
//Serial.println("CAN OBD-II engine RPM");
//CAN.setClockFrequency(8e6);
// start the CAN bus at 500 kbps
if (!CAN.begin(500E3)) {
Serial.println("Starting CAN failed!");
while (1);
}
// add filter to only receive the CAN bus ID's we care about
if (useStandardAddressing) {
CAN.filter(0x7e8);
} else {
CAN.filterExtended(0x18daf110);
}
}
void loop() {
if (useStandardAddressing) {
CAN.beginPacket(0x7df, 8);
} else {
CAN.beginExtendedPacket(0x98DB33F1, 8);
}
CAN.write(0x02); // number of additional bytes
CAN.write(0x01); // show current data
CAN.write(0x0d); // Vehicle Speed
CAN.endPacket();
// wait for response
while (CAN.parsePacket() == 0 ||
CAN.read() < 3 || // correct length
CAN.read() != 0x41 || // correct mode
CAN.read() != 0x0d); // correct PID
int Vss = (CAN.read() /* * 256.0)*/ + CAN.read())/* / 4.0*/;
//Serial.print("Vehicle Speed = ");
Serial.println(Vss);
//tone(3, Vss);
//delay(1000);
}
it compile and upload very well but it does not work.
Sketch uses 7236 bytes (94%) of program storage space. Maximum is 7680 bytes.
Global variables use 649 bytes (63%) of dynamic memory, leaving 375 bytes for local variables. Maximum is 1024 bytes.