|
Post by deadman1966 on Oct 14, 2019 8:24:26 GMT
I am getting the following error on subroutine that reads a ultrasound sensor.
Sensor_Func:62:38: error: 'pulseIn' was not declared in this scope duration = pulseIn(epin, HIGH,50000);
My app uses SPI on the mega at 50,51,52 and digital pin 48 as CS pin. Can this be done in the shieldbuddy, pin 47 and 48 are also CS pins for 2 other spi devices on the same bus.
Can anyone point me in the right direction on how eprom and progmem works under shieldbuddy I am porting an application from a mega2560 board that was sending commands to an sql database, all the command strings where stored in the program memory, and all the setup parameters are being stored in the eprom and read back at boot up. It appears all that code is gonna need a lot of rework and i don't know where to start. these are the subs that stored values
int eepromReadInt(int address){ int value = 0x0000; value = value | (EEPROM.read(address) << 8); value = value | EEPROM.read(address+1); return value; } void eepromWriteInt(int address, int value){ EEPROM.write(address, (value >> 8) & 0xFF ); EEPROM.write(address+1, value & 0xFF); } float eepromReadFloat(int address){ union u_tag { byte b[4]; float fval; } u; u.b[0] = EEPROM.read(address); u.b[1] = EEPROM.read(address+1); u.b[2] = EEPROM.read(address+2); u.b[3] = EEPROM.read(address+3); return u.fval; } void eepromWriteFloat(int address, float value){ union u_tag { byte b[4]; float fval; } u; u.fval=value;
EEPROM.write(address , u.b[0]); EEPROM.write(address+1, u.b[1]); EEPROM.write(address+2, u.b[2]); EEPROM.write(address+3, u.b[3]); }
my sql strings were put into program memory this way
// SQL DATA LOGS const char Chem_Log[] PROGMEM = ("INSERT INTO enviro1.Chem_Log (T,pH1,pH2,TDS1,TDS2,CO2) VALUES "); const char Geophys_Log[] PROGMEM = ("INSERT INTO enviro1.Geophys_Log (T,BARO,MgX,MgY,MgZ) VALUES "); const char Optics_Log[] PROGMEM = ("INSERT INTO enviro1.Optics_Log (T,LI,UV) VALUES "); const char Tanks_Log[] PROGMEM = ("INSERT INTO enviro1.Tanks_Log (T,TT,T1,T2,T3,T4) VALUES "); const char Temps_Log[] PROGMEM = ("INSERT INTO enviro1.Temps_Log (T,TP,RH,TP0,TP1,TP2,TP3,TP4) VALUES "); const char Noise_Log[] PROGMEM = ("INSERT INTO enviro1.Noise_Log (T,P,CN,CD,CL,SD,SE) VALUES "); const char Disturber_Log[] PROGMEM = ("INSERT INTO enviro1.Disturber_Log (T,P,CN,CD,CL,SD,SE) VALUES "); const char Lightning_Log[] PROGMEM = ("INSERT INTO enviro1.Lightning_Log (T,P,CN,CD,CL,SD,SE) VALUES "); const char Lightning_Update[] PROGMEM = ("INSERT INTO enviro1.Lightning_Update (T,P,CN,CD,CL,SD,SE,NF,SR,WD,C,M) VALUES ");
I would pass a string to this sub and it would read the strings from program memory the below is a snippet as there is a switch case statement following with 30 entries if i pass Chem_log into it it gets me the insert statement above this all does rely on a library called Pstring which i am sure is fully compatible yet.
void progmem_sql (char input, int cmd) { //*****
int k; int temp; char myChar; char myinputy = input; P } if (cmd > 0){ // SerialASC.print("progmem_sql command received: "); // SerialASC.println(my_query_string); }
|
|
|
Post by Admin on Oct 14, 2019 10:57:35 GMT
The PulseIn() functions are not currently supported but we will add these in the next release later this week (we have this working already). The PWM measurement functions are the best way to make frequency measurements (section 2.17 in the user manual) but the API is not the same as PulseIn.
Pstring should work but we have never come across this before. Where can we get it?
PROGMEM has no effect on the ShieldBuddy and can be ignored.
The SPI using pin48 as the chipselect needs to be implemented using a bit-bashed driver:
#include "Spi_Illd.h"
// Initialise the SPI SoftSPi_CS_SpiInit(48);
// Make an SPI transaction RxData8 = SoftSPi_CS_Spi_Transfer(48, TxData8, SPIx_LAST);
The EEPROM functions are similar to the Arduino style but there are some exceptions. This is covered in section 2.9 of the user manual.
|
|
|
Post by deadman1966 on Oct 14, 2019 16:16:17 GMT
You can get Pstring here arduiniana.org/libraries/pstring/I will look at the PWM functions but the use is not reading frequency its just measuring the time to the pulse since every library for the HC-SR04 uses pulsein i would suspect that this sensor is unusable until an alternate way to do that is done. When you say progmem has no effect does that mean there is no way to store strings in the program memory, if so that means my program is never gonna work on the shieldbuddy since is uses progmem to store all the strings otherwise i run out of memory on the mega2560 the original sketch basically uses all the mega memory leaving around 2220 bytes at run time. I will try the SPI stuff today on basic sketch to just try and get the CAN card, RTC, and Network card to work. That means 3 devices on the same SPI bus. I am wondering how i am gonna do that when using 3 different CS pins for 3 different devices if i declare it as 48 in your example how do i later read from the device that is on pin 49. It seems once i declare it i can only use one.
|
|
|
Post by Admin on Oct 14, 2019 16:23:14 GMT
The const keyword puts the strings into ROM so PROGMEM is not required and is ignored.
Regarding the SPI chip selects, this will work:
#include "Spi_Illd.h"
// Initialise the SPI SoftSPi_CS_SpiInit(48); pinMode(47, OUTPUT); pinMode(49, OUTPUT);
// Make an SPI transaction RxData8 = SoftSPi_CS_Spi_Transfer(48, TxData8, SPIx_LAST); RxData8 = SoftSPi_CS_Spi_Transfer(47, TxData8, SPIx_LAST); RxData8 = SoftSPi_CS_Spi_Transfer(49, TxData8, SPIx_LAST);
|
|
|
Post by deadman1966 on Oct 14, 2019 19:09:05 GMT
Thanks for all the help
Should i change this
const char Chem_Log[] PROGMEM = ("INSERT INTO enviro1.Chem_Log (T,pH1,pH2,TDS1,TDS2,CO2) VALUES ");
to
const char Chem_Log[] = ("INSERT INTO enviro1.Chem_Log (T,pH1,pH2,TDS1,TDS2,CO2) VALUES ");
and would i read them back differently than this
for (k = 0; k < strlen_P(input); k++) { myChar = pgm_read_byte_near(input + k); my_query_string.print(myChar); }
I am wondering if the "pgm_read_byte_near is implemented?
The idea in the mega was to keep all the strings out of ram at runtime i would think i would fill program memory even in the shieldbuddy if not done this way. I originally just declared the strings but i ram out ram at runtime in the mega that way. Using pgm_read_byte_near resolved that leaving me around 2200 bytes of static ram at run time.
|
|
|
Post by deadman1966 on Oct 14, 2019 19:17:59 GMT
I read the section on PWM measurements but don't think that is gonna working for the ultrasonic sensors i believe it said minimum was 5.96 hz. The sensors just time a single pulse on the pin. May have to wait till the pulseIn is done to fix that section of my code.
|
|
|
Post by Admin on Oct 15, 2019 7:16:17 GMT
None of the PROGMEM and pgm_read_byte_near() tricks are required on the ShieldBuddy due to the Aurix architecture. You can just write normal C/C++ code. These tricks are required due to the way the AVR processor and compiler are designed. In the ShieldBuddy PROGMEM is thrown away. pgm_read_byte_near() is defined as:
#define pgm_read_byte_near(addr) (*(const unsigned char *)(addr))
|
|
|
Post by Admin on Oct 15, 2019 8:52:38 GMT
|
|
|
Post by Admin on Oct 15, 2019 9:04:25 GMT
PString seems to work OK.
|
|
|
Post by deadman1966 on Oct 15, 2019 19:16:20 GMT
********************************************************************************* After installing the files provided i am now seeing errors on the test program i posted under my DS3232 thread posted earlier it won't compile now In file included from C:\Program Files (x86)\Arduino\hardware\aurduino_Dx/aurix/cores/aurduino/WString.h:29:0,
from C:\Program Files (x86)\Arduino\hardware\aurduino_Dx/aurix/cores/aurduino/Arduino.h:38,
from C:\Program Files (x86)\Arduino\hardware\aurduino_Dx/aurix/variants/tc275/Variant.h:26,
from <command-line>:0:
C:\Users\Sysop\Documents\Arduino\libraries\Time\DateStrings.cpp: In function 'char* monthStr(uint8_t)':
C:\Users\Sysop\Documents\Arduino\libraries\Time\DateStrings.cpp:72:64: error: 'pgm_read_ptr' was not declared in this scope
strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(monthNames_P[month])));
^
C:\Program Files (x86)\Arduino\hardware\aurduino_Dx/aurix/cores/aurduino/avr/pgmspace.h:23:45: note: in definition of macro 'strcpy_P'
#define strcpy_P(dest, src) strcpy((dest), (src))
^
C:\Users\Sysop\Documents\Arduino\libraries\Time\DateStrings.cpp: In function 'char* dayStr(uint8_t)':
C:\Users\Sysop\Documents\Arduino\libraries\Time\DateStrings.cpp:86:59: error: 'pgm_read_ptr' was not declared in this scope
strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(dayNames_P[day])));
^
C:\Program Files (x86)\Arduino\hardware\aurduino_Dx/aurix/cores/aurduino/avr/pgmspace.h:23:45: note: in definition of macro 'strcpy_P'
#define strcpy_P(dest, src) strcpy((dest), (src))
^
Multiple libraries were found for "DS3232RTC.h" Used: C:\Users\Sysop\Documents\Arduino\libraries\DS3232RTC Multiple libraries were found for "TimeLib.h" Used: C:\Users\Sysop\Documents\Arduino\libraries\Time Multiple libraries were found for "Streaming.h" Used: C:\Users\Sysop\Documents\Arduino\libraries\Streaming Multiple libraries were found for "SFE_BMP180.h" Used: C:\Users\Sysop\Documents\Arduino\libraries\SFE_BMP180 Not used: C:\Users\Sysop\Documents\Arduino\libraries\BMP180_Breakout_Arduino_Library Using library DS3232RTC at version 1.2.6 in folder: C:\Users\Sysop\Documents\Arduino\libraries\DS3232RTC Using library Time at version 1.5 in folder: C:\Users\Sysop\Documents\Arduino\libraries\Time Using library Streaming at version 5.0.0 in folder: C:\Users\Sysop\Documents\Arduino\libraries\Streaming Using library SFE_BMP180 in folder: C:\Users\Sysop\Documents\Arduino\libraries\SFE_BMP180 (legacy) exit status 1 Error compiling for board ShieldBuddyTC275_Dx.
|
|
|
Post by Admin on Oct 15, 2019 20:10:05 GMT
Unfortunately the modification to define pgm_read_ptr was omitted from the last release. This has now been fixed. Please download the add-in again and the problem should be fixed.
|
|