I have written the below code for interfacing my Nokia LCD with the microcontroller PIC16F877A.
I have downloaded the library file from Microelectronics website and pasted into my folder. However, I keep getting the below error messages from.
I am using MicroC for PIC 7.5.
23 304 error: Unterminated string literal, skipped the line
Nokia_3310_Write_Text("electrocardiogram?5,1); // write text
1 error in preprocessor.
C:\Users\123\Desktop\New design with PIC16F877A and nOKIA 3310\my new design\PIC16F877AandNOKIA5110.c
21 324 Undeclared identifier 'Nokia_3310_LCD_Init' in expression PIC16F877AandNOKIA5110.c
22 324 Undeclared identifier 'Nokia_3310_LCD_Clear' in expression PIC16F877AandNOKIA5110.c
24 324 Undeclared identifier 'Nokia_3310_LCD_Clear' in expression PIC16F877AandNOKIA5110.c
25 324 Undeclared identifier 'Nokia_3310' in expression PIC16F877AandNOKIA5110.c
25 402 ; expected, but '_Image' found PIC16F877AandNOKIA5110.c
25 424 '}' expected ';' found PIC16F877AandNOKIA5110.c
33 312 Internal error '' PIC16F877AandNOKIA5110.c 0 102 Finished (with errors): 25 May 2021, 14:47:45 PIC16F877AandNOKIA5110.mcppi``
// Nokia 3310 or 5110 LCD pinout settings
sbit Nokia_3310_SCLK at RB4_bit;
sbit Nokia_3310_SDA at RB3_bit;
sbit Nokia_3310_DC at RB2_bit;
sbit Nokia_3310_CS at RB1_bit;
sbit Nokia_3310_REST at RB0_bit;
// Pin direction
sbit Nokia_3310_SCLK_dir at TRISB4_bit;
sbit Nokia_3310_SDA_dir at TRISB3_bit;
sbit Nokia_3310_DC_dir at TRISB2_bit;
sbit Nokia_3310_CS_dir at TRISB1_bit;
sbit Nokia_3310_REST_dir at TRISB0_bit;
unsigned short i = 0;
char *txt;
void short_to_String(unsigned short j) {
txt[0] = j / 100;
txt[1] = (j / 10) % 10;
txt[2] = j % 10;
}
void main() {
Nokia_3310_LCD_Init();// initialize the Nokia 3310 or 5110 LCD
Nokia_3310_LCD_Clear();// Clear the Nokia 3310 or 5110 LCD
Nokia_3310_Write_Text("electrocardiogram?5, 1); // write text
Delay_ms(2000);
Nokia_3310_LCD_Clear();// Clear the Nokia 3310 or 5110 LCD
Nokia_3310 _Image(erste_Bild);// Draw picture
Delay_ms(3000);
Nokia_3310_LCD_Clear();// Clear the Nokia 3310 or 5110 LCD
for (;;) {
short_to_String(i); // convert short to string
Nokia_3310_Write_Text(txt, 40, 3);//write text
i++;
Delay_ms(1500);
}
}
Related
I trying to use custom pins for SPI on the pico-mini-02 board. The board has esp32 (pico-v3-02). I'm using Arduino IDE (with arduino-esp32) and windows 10.
When I try to use the SPI example (multiple buses example), I'm getting Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. error. I have decoded the exception backtrace
0x40080f31: __pinMode at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\cores\esp32\esp32-hal-gpio.c line 115
0x400d0f3a: spiAttachSCK at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\cores\esp32\esp32-hal-spi.c line 87
0x400d0db2: SPIClass::begin(signed char, signed char, signed char, signed char) at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\libraries\SPI\src\SPI.cpp line 57
0x400d0c2b: setup() at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\libraries\SPI\examples\SPI_Multiple_Buses/SPI_Multiple_Buses.ino line 67
0x400d190a: loopTask(void*) at C:\Users\newto\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.5\cores\esp32\main.cpp line 32
0x40085fa5: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143
The full error message:
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 271414342, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x40080f31 PS : 0x00060730 A0 : 0x800d0f3d A1 : 0x3ffb1f30
A2 : 0x0000000e A3 : 0x00000002 A4 : 0x3ffb8364 A5 : 0x00000001
A6 : 0x00000000 A7 : 0x00000004 A8 : 0x3f400674 A9 : 0xaaaaaaaa
A10 : 0xaaaaaaaa A11 : 0x00000030 A12 : 0x3ffb82cc A13 : 0x00000000
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x00000009 EXCCAUSE: 0x0000001c
EXCVADDR: 0xaaaaaaaa LBEG : 0x400d1258 LEND : 0x400d1265 LCOUNT : 0x00000000
ELF file SHA256: 0000000000000000
Backtrace: 0x40080f31:0x3ffb1f30 0x400d0f3a:0x3ffb1f50 0x400d0db2:0x3ffb1f70 0x400d0c2b:0x3ffb1f90 0x400d190a:0x3ffb1fb0 0x40085fa5:0x3ffb1fd0
Rebooting...
ets Jul 29 2019 12:21:46
Any help would be appreciated.
The sketch:
/* The ESP32 has four SPi buses, however as of right now only two of
* them are available to use, HSPI and VSPI. Simply using the SPI API
* as illustrated in Arduino examples will use VSPI, leaving HSPI unused.
*
* However if we simply intialise two instance of the SPI class for both
* of these buses both can be used. However when just using these the Arduino
* way only will actually be outputting at a time.
*
* Logic analyser capture is in the same folder as this example as
* "multiple_bus_output.png"
*
* created 30/04/2018 by Alistair Symonds
*/
#include <SPI.h>
// Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus
#ifdef ALTERNATE_PINS
#define VSPI_MISO 2
#define VSPI_MOSI 4
#define VSPI_SCLK 0
#define VSPI_SS 33
#define HSPI_MISO 26
#define HSPI_MOSI 27
#define HSPI_SCLK 25
#define HSPI_SS 32
#else
#define VSPI_MISO MISO
#define VSPI_MOSI MOSI
#define VSPI_SCLK SCK
#define VSPI_SS SS
#define HSPI_MISO 12
#define HSPI_MOSI 13
#define HSPI_SCLK 14
#define HSPI_SS 15
#endif
static const int spiClk = 1000000; // 1 MHz
//uninitalised pointers to SPI objects
SPIClass * vspi = NULL;
SPIClass * hspi = NULL;
void setup() {
//initialise two instances of the SPIClass attached to VSPI and HSPI respectively
vspi = new SPIClass(VSPI);
hspi = new SPIClass(HSPI);
//clock miso mosi ss
#ifndef ALTERNATE_PINS
//initialise vspi with default pins
//SCLK = 18, MISO = 19, MOSI = 23, SS = 5
vspi->begin();
#else
//alternatively route through GPIO pins of your choice
vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
#endif
#ifndef ALTERNATE_PINS
//initialise hspi with default pins
//SCLK = 14, MISO = 12, MOSI = 13, SS = 15
hspi->begin();
#else
//alternatively route through GPIO pins
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS
#endif
//set up slave select pins as outputs as the Arduino API
//doesn't handle automatically pulling SS low
pinMode(VSPI_SS, OUTPUT); //VSPI SS
pinMode(HSPI_SS, OUTPUT); //HSPI SS
}
// the loop function runs over and over again until power down or reset
void loop() {
//use the SPI buses
vspiCommand();
hspiCommand();
delay(100);
}
void vspiCommand() {
byte data = 0b01010101; // junk data to illustrate usage
//use it as you would the regular arduino SPI API
vspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(VSPI_SS, LOW); //pull SS slow to prep other end for transfer
vspi->transfer(data);
digitalWrite(VSPI_SS, HIGH); //pull ss high to signify end of data transfer
vspi->endTransaction();
}
void hspiCommand() {
byte stuff = 0b11001100;
hspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(HSPI_SS, LOW);
hspi->transfer(stuff);
digitalWrite(HSPI_SS, HIGH);
hspi->endTransaction();
}
Hi Mate I tried the code and it works. I have selected AI Thinker ESP32 that matches my board,and I have selected Flash Mode QIO and also DIO: both working fine. If you may still have the issue I would suggest to select DOUT or DIO.
Basically please check if your board matches the one selected on Tools->Board and check also the selection of 'Flash mode'.
Not all chips support all of these modes. The datasheet is the best source to know what supports what.
DIO - SPI host uses the "Dual I/O Fast Read" command (BBh). Two SPI pins are used to write the flash address part of the command, and to read flash data out. Therefore these phases need half the clock cycles compared to standard SPI.
DOUT - SPI host uses the "Dual Output Fast Read" command (3Bh). Two SPI pins are used to read flash data out. Slightly slower than DIO, because the address is written via the single MOSI data pin.
QIO - SPI host uses the "Quad I/O Fast Read" command (EBh). Four SPI pins are used to write the flash address part of the command, and to read flash data out. Therefore these phases need a quarter the clock cycles compared to standard SPI.
QOUT - SPI host uses the "Quad Output Fast Read" command (6Bh). Four SPI pins are used to read the flash data out. Slightly slower than QIO, because the address is written via the single MOSI data pin.
ESP-IDF defaults to DIO because some flash chips use a mode bit to enable QIO & QOUT support, and this can vary between manufacturers.
If using DIO/DOUT mode, GPIOs 9 & 10 are available for other uses. However note that if they are wired to the SPI flash chip (as they are in WROOM, for example) then the SPI flash chip may use them for other pin functions. Consult the SPI flash chip data sheet to be sure.
Very interesting discussion on this subject here: https://www.esp32.com/viewtopic.php?t=1250
Hope this helps. All the best.
I am beginner in arduino. Here I tried to burn/upload a code from arduino IDE. Code executes successfully but problem is on uploading time. It shows Verification error , first mismatch at type 0x0000. 0x62 !=0x0c. I am trying to burn it from windows pc. Here is my code
int trigPin = 11; // Trigger
int echoPin = 12; // Echo
long duration, cm, inches;
void setup() {
Serial.begin (9600);
//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// Convert the time into a distance
cm = (duration/2) / 29.1; // Divide by 29.1 or multiply by 0.0343
inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(250);
}
Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino
Uno" Sketch uses 444 bytes (1%) of program storage space. Maximum is
32256 bytes. Global variables use 9 bytes (0%) of dynamic memory,
leaving 2039 bytes for local variables. Maximum is 2048 bytes. An
error occurred while uploading the sketch avrdude: verification error,
first mismatch at byte 0x0000 0x62 != 0x0c avrdude: verification
error; content mismatch #Piglet thanks for advice . Here is error
details
There are plenty of posts online about that error. You should be able to find them as well.
The most suggested solution is to burn the bootloader as in this post:
https://forum.arduino.cc/index.php?topic=453997.0
The bootloader is a small program that is on the Arduino Unos microcontroller. It is necessary to get your application on the the microcontroller via the USB interface.
You would need a IPS programmer otherwise.
To burn the bootloader you need a dedicated AVR ISP programmer or a second Arduino. You can get them for little money online.
I am trying to use a PN532 (v3) board with an Arduino UNO and libnfc for my university project. One problem I have stumbled upon is that libnfc-1.7.1 gives me the following error when I invoke nfc-list:
debug libnfc.general log_level is set to 3
debug libnfc.general allow_autoscan is set to false
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 1 device(s) defined by user
debug libnfc.general #0 name: "PN532 NFC Board on Arduino", connstring: "pn532_uart:/dev/ttyUSB0:115200"
nfc-list uses libnfc 1.7.1
debug libnfc.driver.pn532_uart Attempt to open: /dev/ttyUSB0 at 115200 bauds.
debug libnfc.bus.uart Serial port speed requested to be set to 115200 bauds.
debug libnfc.chip.pn53x Diagnose
debug libnfc.chip.pn53x Timeout value: 500
debug libnfc.bus.uart TX: 55 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00
debug libnfc.chip.pn53x SAMConfiguration
debug libnfc.chip.pn53x Timeout value: 1000
debug libnfc.bus.uart TX: 00 00 ff 03 fd d4 14 01 17 00
debug libnfc.bus.uart Timeout!
debug libnfc.driver.pn532_uart Unable to read ACK
error libnfc.driver.pn532_uart pn53x_check_communication error
debug libnfc.chip.pn53x InRelease
debug libnfc.bus.uart TX: 00 00 ff 03 fd d4 52 00 da 00
debug libnfc.bus.uart Timeout!
debug libnfc.driver.pn532_uart Unable to read ACK
debug libnfc.general Unable to open "pn532_uart:/dev/ttyUSB0:115200".
nfc-list: ERROR: Unable to open NFC device: pn532_uart:/dev/ttyUSB0:115200
I have no issues using the reader with Arduino, I can upload sketches and the reader interacts with tags. The reader is in SPI mode, and when I invoke nfc-list the LEDs blink, therefore the only thing I can think of is some sort of issue with libnfc.
I hope someone can help,any suggestions would be amazing! :)
Thank you!
Connections
PN532 V3
Arduino.1
Arduino.2
File Configurations
/etc/nfc/libnfc.conf
# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to set manually a device
# configuration using file or environment variable
allow_autoscan = false
# Allow intrusive auto-detection (default: false)
# Warning: intrusive auto-detection can seriously disturb other devices
# This option is not recommended, user should prefer to add manually his device.
allow_intrusive_scan = false
# Set log level (default: error)
# Valid log levels are (in order of verbosity): 0 (none), 1 (error), 2 (info), 3 (debug)
# Note: if you compiled with --enable-debug option, the default log level is "debug"
log_level = 3
# Manually set default device (no default)
# To set a default device, you must set both name and connstring for your device
# Note: if autoscan is enabled, default device will be the first device available in device
list.
device.name = "PN532 NFC Board on Arduino"
device.connstring = "pn532_uart:/dev/ttyUSB0:115200"
uartnfc.info
#include <PN532.h>
#define SCK 13
#define MOSI 11
#define SS 10
#define MISO 12
PN532 nfc(SCK, MISO, MOSI, SS);
uint8_t buffer[32];
void setup(void) {
Serial.begin(115200); //460800, 115200
Serial.flush();
nfc.begin();
}
void loop(void) {
int b = Serial.available();
if (b >= 5){
Serial.readBytes((char*)buffer, 5);
if(buffer[0] == 0x55){
//handle wake up case
while(Serial.available() < 5); //wait the command
b = Serial.readBytes((char*)buffer+5, 5);
//send raw command to pn532
//get length of package :
// (PREAMBLE + START + LEN + LCS) + (TFI + DATA[0...n]) + (DCS + POSTAMBLE)
uint8_t l = buffer[8] + 2;
while(Serial.available() < l); //wait the command
//read command from uart
Serial.readBytes((char*)buffer+10, l);
//send raw command to pn532
nfc.sendRawCommandCheckAck(buffer, l+10);
//read pn532 answer
nfc.readRawCommandAnswer(buffer, l+10);
}else{
//normal case
//get length of package :
// (PREAMBLE + START + LEN + LCS) + (TFI + DATA[0...n]) + (DCS + POSTAMBLE)
uint8_t l = buffer[3] + 2;
//read command from uart
//while(Serial.available() < l); //wait the command
//Serial.readBytes((char*)buffer+5, l);
uint8_t br = l;
uint8_t* bufptr = buffer + 5;
while(br){
if(Serial.available()){
*bufptr++ = Serial.read();
--br;
}
}
//send raw command to pn532
nfc.sendRawCommandCheckAck(buffer, l+5);
//read pn532 answer
nfc.readRawCommandAnswer(buffer, l+5);
}
}
}
Used Resources
http://nfc-tools.org/index.php/Libnfc:Arduino - Used to install libnfc
https://github.com/gunmetal313/mfocuino - Uploaded the sketch uartnfc.ino and imported the libraries (mfocuino/mfocuino-read-only/nfcreader/arduino/libraries/PN532/) into the Arduino IDE.
Things I have already tried to fix the problem
Why "No NFC device found" with libnfc and PN532 SHIELD
PN532 Unable to open NFC device
https://github.com/nfc-tools/libnfc/issues/507
https://forums.adafruit.com/viewtopic.php?f=19&t=58188
https://superuser.com/questions/1409108/nfc-unable-to-open-nfc-device
I almost gave up having the same problem. For me it finally worked when using 9600 baud in the Arduino Sketch and libnfc config.
In the C file in simplesample_mqtt.c, which connects Arduino to the Azure IoT hub, I need to use the IRsend and IrRemoteESP8266 libraries to send an infrared signal with Azure IoT hub.
#include <IRremoteESP8266.h>
#include <IRsend.h>
IRsend irsend(10); // An IR LED is controlled by GPIO pin 4 (D2)
I don't have any problem when I use this code in my main Ardunio file. But when I use these includes in a C file (implesample_mqtt.c), I get this error from line 3: "unknown type name 'IRsend'".
error full info :
Arduino: 1.8.2 (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (3M SPIFFS)"
In file included from sketch\simplesample_mqtt.c:29:0:
C:\Program Files (x86)\Arduino\libraries\IRremoteESP8266\src/IRsend.h:29:1: error: unknown type name 'class'
class IRsend {
C:\Program Files (x86)\Arduino\libraries\IRremoteESP8266\src/IRsend.h:29:14: error: expected '=', ',', ';', 'asm' or 'attribute' before '{' token
class IRsend {
simplesample_mqtt.c:31: error: unknown type name 'IRsend'
IRsend irsend(10); // An IR LED is controlled by GPIO pin 4 (D2)
simplesample_mqtt.c:31: error: expected declaration specifiers or '...' before numeric constant
IRsend irsend(10); // An IR LED is controlled by GPIO pin 4 (D2)
exit status 1
unknown type name 'IRsend'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I solved this problem. The reason for this is because main ardunio is c++ and simplesample_mqtt.c is c code and we have to use c++ code in c code :
i main ardunio file you have to declare function like this :
extern "C" void TurnOn();
void TurnOn()
{
digitalWrite(RELAY_SONOFF, HIGH);
digitalWrite(LED_SONOFF, HIGH);
}
and use this function in c code :
void TurnOn();
EXECUTE_COMMAND_RESULT TurnOn(ContosoAnemometer* device)
{
(void)device;
TurnOn();
(void)printf("Turning fan on.\r\n");
return EXECUTE_COMMAND_SUCCESS;
}
I have been able to get outputs working on my PIC and can make a bunch of LEDs dance on and off as I set various output latches high/low. However, I'm having a lot o difficulty reading in the state of a pin.
See the code below. I set up my config, and define the TRISC as input and TRISB as output. In an infinite loop, I check to see whether RC6 is high or low, and set the entire B latch high or low depending on the result.
#include <htc.h>
__CONFIG(1, FOSC_IRC & FCMEN_OFF & IESO_OFF);
__CONFIG(2, PWRTEN_OFF & BOREN_OFF & WDTEN_OFF);
__CONFIG(3, MCLRE_OFF);
__CONFIG(4, STVREN_ON & LVP_OFF & DEBUG_OFF);
__CONFIG(5, 0xFFFF);
__CONFIG(6, 0xFFFF);
__CONFIG(7, 0xFFFF);
void main(void)
{
TRISC = 0xFF; // input
TRISB = 0x00; // output
while (1)
{
if (PORTCbits.RC6 == 0)
LATB = 0b00000000;
else
LATB = 0b11111111;
}
return;
}
The code compiles fine with no warnings or errors. If my code logic is simply setting latches high and low then that works fine, but I haven't been able to successfully read the state of a pin.
Any ideas?
I'm using a PIC18F14K50 and MPLAB v8.43 and the HiTech ANSI C Compiler.
My connections are +5V to the VDD (pin 1), VSS (pin 20) to ground. I have +5V to C6 (pin 8), and a 100K resistor and LED from B7 (pin 10) to ground. To toggle RC6, I connect/disconncet the wire to C6.
┌────────┐
+5v -│ 01 20 │- gnd
-│ 02 19 │-
-│ 03 18 │-
-│ 04 17 │-
-│ 05 16 │-
-│ 06 15 │-
-│ 07 14 │-
+5v -│ 08 13 │-
-│ 09 12 │-
led -│ 10 11 │-
└────────┘
The ADC pins on the PICs unfortunately are configured as analog inputs on powerup. You need to disable the ADC functionality on that pin to use it as a digital input.
Clearing bit 0 of ANSELH will set RC6 to digital input. Then your code will work.
This is documented in the datasheet in section 9.4 : Port Analog Control
PIC18F/LF1XK50 Datasheet
Setting...
TRISC = 1; // input
...should set only pin RC0 of PORTC as input pin, all other pins are defined as output.
So PORTCbits.RC6 == 0 should not return correct input state of in RC6 pin.
TRISC = 255 should set all pins of PORTC as input.
It is worth mentioning that some other PIC18 variants are set up differently:
On PIC18F4520 and PIC18F4680 you need to configure pins as digital it trough a ADCON1 register instead of ANSELH.
Setting a bit to 1 will make a pin digital.
Besides this you need to make them input pins by setting a bit to 1 in the corresponding TRIS register.