I am using an Arduino and a DS1307. I have acquired the time from the RTC no problem but when i try to apply the setSyncProvider call i get a few errors which are implying to my ds1307.h files in my library. attached is my code and errors. These errors , I am not quite sure what they are and mean. Do I need to go in notepad++ and change lines 66-68 to something or alter the .h in anyway? Does any body have an idea? Your help is most appreciated. By the way, the code is from the Arduino Cookbook so i know it works, its just smething in that .h file...... i think
#include <Time.h>
#include <Wire.h>
#include <DS1307.h> // a basic DS1307 library that returns time as a time_t
void setup() {
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
}
void loop() {
if(Serial.available()) {
time_t t = processSyncMessage();
if(t > 0) {
RTC.set(t); // set the RTC and the system time to the received value
setTime(t);
}
}
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay() {
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
// utility function for digital clock display: prints preceding colon and
// leading 0.
//
void printDigits(int digits) {
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
/* code to process time sync messages from the serial port */
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by Unix time_t
#define TIME_HEADER 'T' // Header tag for serial time sync message
time_t processSyncMessage() {
while(Serial.available() >= TIME_MSG_LEN ) {
char c = Serial.read() ;
Serial.print(c);
if( c == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++) {
c = Serial.read();
if( c >= '0' && c <= '9') {
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
return pctime;
}
}
return 0;
}
My errors.......................................
sketch_dec27d.ino: In function 'void setup()':
sketch_dec27d:14: error: no matches converting function 'get' to type 'time_t (*)()'
C:\Users\AlbertR\Desktop\arduino-1.0.3\libraries\DS1307/DS1307.h:66: error: candidates are: void DS1307::get(int*, boolean)
C:\Users\AlbertR\Desktop\arduino-1.0.3\libraries\DS1307/DS1307.h:67: error: int DS1307::get(int, boolean)
sketch_dec27d.ino: In function 'void loop()':
sketch_dec27d:27: error: no matching function for call to 'DS1307::set(time_t&)'
C:\Users\AlbertR\Desktop\arduino-1.0.3\libraries\DS1307/DS1307.h:68: note: candidates are: void DS1307::set(int, int)
Related
I have written a C code for PCM PIC 16 Microcontroller. I have now replaced the board with a PCH PIC 18. I am having issues configuring the new board. Here is an excerpt of my code where I am getting the errors.
#include "i2c_custom.h"
const int getIIC_period_us(){
return (1000/IIC_CLOCK_KHz);
}
#ifdef USE_IIC_CCS_FUNCTION
int i2c_custom_read(int ack) {return i2c_read(ack);}
void i2c_custom_stop() {i2c_stop();}
void i2c_custom_start() {i2c_start();}
int i2c_custom_write(int8 data) {return i2c_write(data);}
#else
int i2c_custom_read(int ack) {
int data=0;
for(int i=7;i>=-1;i--)
{
if(i>=0){
i2c_custom_delay_us(IIC_period_4);
data |= (input(hw_IIC_SDA)<<i);
}else{
if(ack) output_low(hw_IIC_SDA);
else output_high(hw_IIC_SDA);
i2c_custom_delay_us(IIC_period_4);
}
i2c_custom_delay_us(IIC_period_4);
output_high(hw_IIC_SCL);
i2c_custom_delay_us(IIC_period_2);
output_low(hw_IIC_SCL);
}
return data;
}
void i2c_custom_stop() {
if(input_state(hw_IIC_SDA) || input_state(hw_IIC_SCL)){
output_low(hw_IIC_SCL);
output_low(hw_IIC_SDA);
i2c_custom_delay_us(IIC_period_4);
}
output_high(hw_IIC_SCL);
i2c_custom_delay_us(IIC_period_4);
output_high(hw_IIC_SDA);
i2c_custom_delay_us(IIC_period_4);
}
void i2c_custom_start() {
if(!input_state(hw_IIC_SDA) || !input_state(hw_IIC_SCL)){
output_high(hw_IIC_SDA);
output_high(hw_IIC_SCL);
i2c_custom_delay_us(IIC_period_4);
}
output_low(hw_IIC_SDA);
i2c_custom_delay_us(IIC_period_4);
output_low(hw_IIC_SCL);
}
int i2c_custom_write(int8 data) {
int ack=0;
for(int i=7;i>=-1;i--)
{
if(i>=0){
if((data&(0x01<<i)) ==0) output_low(hw_IIC_SDA);
else output_high(hw_IIC_SDA);
i2c_custom_delay_us(IIC_period_4);
}else{
i2c_custom_delay_us(IIC_period_4);
ack= input(hw_IIC_SDA);
}
i2c_custom_delay_us(IIC_period_4);
output_high(hw_IIC_SCL);
i2c_custom_delay_us(IIC_period_2);
output_low(hw_IIC_SCL);
}
return ack;
}
void i2c_custom_delay_us(int delay){
for(int i=0;i<delay;i++)
delay_us(1);
}
#endif
I am getting the following errors:
Error#51 A numeric expression must appear here :: i2c_read() not supported when using MASTER mode and HW I2C on this device, see i2c_transfer():
Error#112 Function used but not defined: :: i2c_stop() not supported when using HW I2C on this device, see i2c_transfer():
Error#112 Function used but not defined: :: i2c_start() not supported when using HW I2C on this device, see i2c_transfer():
Error#51 A numeric expression must appear here :: i2c_write() not supported when using MASTER mode and HW I2C on this device, see i2c_transfer():
I am not sure if I have to replace i2c_start(),i2c_stop(),i2c_read(), i2c_write() with i2c_transfer(). But I am not sure how to use i2c_transfer().
I would appreciate any help.
I am reading the data from a "Torque Wrench" using "USB Host Shield2.0" and Arduino UNO. I am receiving correct data from my "Torque Wrench" Data is receiving in a array.
But when I started reading data after "for" loop inside Void loop() I am receiving incorrect data. I attached Both output pictures correct and incorrect data.
Basically I am read data from Torque Wrench and send to receiver using Nrf24l01. I am receiving incorrect data.
My question is :- Why I am reading Incorrect data outside "for" loop.
Correct Data inside "for" loop :- enter image description here
Incorrect Data outside "for" loop :- enter image description here
#include <SPI.h> // for SPI communication
#include <nRF24L01.h>
#include <RF24.h>
#include <cdcacm.h>
#include <usbhub.h>
//#include "pgmstrings.h"
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = {'R','x','A','A','A','B'}; // the address the the module
class ACMAsyncOper : public CDCAsyncOper
{
public:
uint8_t OnInit(ACM *pacm);
};
uint8_t ACMAsyncOper::OnInit(ACM *pacm)
{
uint8_t rcode;
// Set DTR = 1 RTS=1
rcode = pacm->SetControlLineState(3);
if (rcode)
{
ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
return rcode;
}
LINE_CODING lc;
lc.dwDTERate = 9600;
lc.bCharFormat = 0;
lc.bParityType = 0;
lc.bDataBits = 8;
rcode = pacm->SetLineCoding(&lc);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
return rcode;
}
USB Usb;
//USBHub Hub(&Usb);
ACMAsyncOper AsyncOper;
ACM Acm(&Usb, &AsyncOper);
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.stopListening();
#if !defined(__MIPSEL__)
while (!Serial);
#endif
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("USB Not Connected");
delay( 200 );
}
void loop() {
Usb.Task();
if( Acm.isReady()) {
uint8_t rcode;
/* reading the keyboard */
if(Serial.available()) {
uint8_t data= Serial.read();
/* sending to the phone */
rcode = Acm.SndData(1, &data);
if (rcode)
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
}
delay(10);
uint8_t buf[64];
uint16_t rcvd = 64;
char text[64];
rcode = Acm.RcvData(&rcvd, buf);
if (rcode && rcode != hrNAK)
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
if ( rcvd ) {
for(uint16_t i=0; i < rcvd; i++ )
{
// Serial.print((char)buf[i]); // correct Data read from torque wrench
text[i] = (char)buf[i];
}
Serial.println(text); // reading wrong data here
//radio.write(&text, sizeof(text));
//Serial.println(text);
}
delay(10);
}
}
Character arrays must be null-terminated to count as C strings.
After the for loop, add text[rcvd] = '\0';
Also, your rcvd is fixed at 64. It needs to be one less than the array size for the null terminator to fit.
I'm in a pickle regarding concepts relating to timers. How can I can I operate a "delay" inside a timer? This is the best way I can frame the question knowing full well what I'm trying to do is nonsense. The objective is: I wish to test the pinState condition 2 times (once initially and then 4 seconds later) but this all needs to happen periodically (hence a timer).
The platform is NodeMCU running a WiFi (ESP8266 chip) and coding done inside Arduino IDE.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth[] = "x"; //Auth code sent via Email
char ssid[] = "x"; //Wifi name
char pass[] = "x"; //Wifi Password
int flag=0;
void notifyOnFire()
{
int pinState = digitalRead(D1);
if (pinState==0 && flag==0) {
delay(4000);
int pinStateAgain = digitalRead(D1);
if (pinStateAgain==0) {
Serial.println("Alarm has gone off");
Blynk.notify("House Alarm!!!");
flag=1;
}
}
else if (pinState==1)
{
flag=0;
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(D1,INPUT_PULLUP);
timer.setInterval(1000L,notifyOnFire);
}
void loop()
{
//Serial.println(WiFi.localIP());
Blynk.run();
timer.run();
}
an easy fix would be to set the periodicity of the timer to be 4000L timer.setInterval(4000L,notifyOnFire); and in notifyOnFire use a static variable and toggle its value whenever notifyOnFire is called
void notifyOnFire()
{
static char state = 0;
if( state == 0)
{
/* Write here the code you need to be executed before the 4 sec delay */
state = 1;
}
else
{
/* Write here the code you need to be executed after the 4 sec delay */
state = 0;
}
}
The nice thing about static variables is that they are initialized only once at compile time and they retain their values after the scope of code changes (In this case function notifyOnFire exits).
I've been trying to achieve serial communication between my arduino-based project and my pc ,i need to send commands to arduino over serial and use "if and else" to call desired function (in parseMessage() function).
I can't use delay() since I'm using interrupts for multiplexing and bit-angle modulation so i had to do serial communication another way around, this is closest I've got to succeess but still I'm getting character skips and unstability in general. and as you know coding is all great except for when you don't know what's wrong with your code, so help me please gods of the internet! ;)
The reason I'm using '#' as end of the string declearation is that I can't be sure that all characters of my command sent to arduino is there when Serial.read() asks for it, there might be more on the way and since atmega328 is faster than serial port Serial.available() might actually return -1 in middle of transmission.
ps : oh, and I can't use String class, It's very expensive, this atmega328 is already sweating under 8x8 RGBLED multiplexing and 4bit-angle modulation and he is gonna have to do even more in future.
ps : and I'm still learning English so pardon me if there is something wrong with the grammer I'm using.
void setup() {
Serial.begin(9600);
}
bool dataRTP = false; // data ready to parse
void loop() {
readSerial();
}
char message[64];
int index = 0;
void readSerial() {
if (Serial.available() > 0)
while (Serial.available() > 0)
if (Serial.peek() != '#') // i'm using '#' as end of string declearation.
message[index++] = Serial.read();
else {
message[index++] = '\n';
dataRTP = true;
break;
}
while (Serial.read() != -1) {} // flushing any possible characters off of
if (dataRTP) // UARTS buffer.
parseMessage();
}
void parseMessage() { // just testing here, actual code would be like :
Serial.print(message); // if (!strcmp(message, "this expression"))
index = 0; // callthisfunction();
dataRTP = false; // else ... etc
}
Just managed to fix this code, seems flushing data off of serial UART wasn't a good idea after all. It's all solved. Here's how code looks now:
void setup() {
Serial.begin(9600);
}
bool dataRTP = false;
void loop() {
readSerial();
}
char message[64];
int index = 0;
void readSerial() {
if (Serial.available() > 0)
while (Serial.available() > 0)
if (Serial.peek() == '#') {
message[index++] = Serial.read();
message[index++] = '\0';
dataRTP = true;
break;
}
else
message[index++] = Serial.read();
if (dataRTP)
parseMessage();
}
void parseMessage() {
Serial.println(message);
index = 0;
dataRTP = false;
}
I am trying to create a small stall at school using and arduino,
the project is to scan items using a barcode scanner enter the price and issue a receipt. the barcode scanner is connected to serial port and keypad and printer are connected via software serial. I am using a 3.5" tv as the display. the items can be identified by the first 3 digits of the barcode. I want to include the item names somewhere in the sketch and match and print them when the string starts with their number.
I have created a sketch with a lot of help from other forum users but the date is being repeatedly printed and not much else is happening. How do I make the date print only once. and also how do I buffer data from serial and software serial before printing.
//#include <TVout.h>
//#include <video_gen.h>
//ARDUINO 1.0 COMPATIBLE ONLY!
//ARDUINO 1.0 COMPATIBLE ONLY!
#include <Time.h>
#include <DS1307RTC.h>
#include <SoftwareSerial.h>
//#include <LiquidCrystal.h>
#include <Thermal.h>
#include <Wire.h>
//TVout TV;
int printer_RX_Pin = 3;
int printer_TX_Pin = 4;
int incomingByte = 0;
Thermal printer(printer_RX_Pin, printer_TX_Pin, 19200);
String readString; // a string to hold incoming data
//SoftwareSerial mySerial(10, 11);
void setup(){
//TV.begin(PAL,120,96);
// TV.select_font(font6x8);
Serial.begin(9600);
//mySerial.begin(9600);
setSyncProvider(RTC.get);
// if (timeStatus() != timeSet )
// Serial.println("Unable to sync with the RTC");
// else
// Serial.println("RTC has set the system time");
//tv.print(scan item) ???
//ITEM SCANNED GETS STORED INTO string.Readstring
//tv print (enter donation Amount)
//INPUT FROM KEYPAD GETS STORED INTO BUFFER1 (KEYPAD IS HOOKED UP TO SOFTWARE SERIAL PINS)
//THEN PRINTER PRINTS TITLE (MAYBE BETTER TO WAIT FOR ALL INPUT BEFORE PRINTING)
printer.justify('C');
//sets text justification (right, left, center) accepts 'L', 'C', 'R'
printer.setSize('L'); // set type size, accepts 'S', 'M', 'L'
printer.println("School Feast "); //print line
printer.setSize('M'); // set type size, accepts 'S', 'M', 'L'
printer.println("My Stall"); //print line
printer.println("My Town");
printer.feed(); //advance one line
printer.println(" My Country");
printer.feed(); //advance one line
}
void serialRead() {
while (Serial.available()) {
delay(10);
if (Serial.available() >0) {
char c = Serial.read();
readString += c;};
}
}
void loop() {
// THEN TIME GETS PRINTED
tmElements_t tm;
if (RTC.read(tm)) {
Serial.print(" ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(" ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
printer.print(" ");
print2digits(tm.Hour);
printer.write(':');
print2digits(tm.Minute);
printer.write(':');
print2digits(tm.Second);
printer.print(" ");
printer.print(tm.Day);
printer.write('/');
printer.print(tm.Month);
printer.write('/');
printer.print(tmYearToCalendar(tm.Year));
printer.println();
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
}
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
if (Serial.available() > 0) {
readString = "";
serialRead();
String Item = readString.substring(0,3);
//THEN ITEM PRINT( IDENTIFY ITEM BY FIRST 3 CHARACTERS OF STRING, HOW??)
Serial.print(Item);
printer.print(Item);
Serial.println();{
//THEN PRINT DONATION AMOUNT(INPUT FROM SOFTWARE SERIAL)
//printer.print(software.serial buffer)
//printer. print("GBP");
//clear display
//tv.clear
}
}
}