LCD shows random characters (MPLAB) - c

I'm trying to connect my LCD screen (16x02 QAPASS) to my PIC16F1937 on MPLAB, but it displays random characters (in this case Chinese characters, question marks and slash) instead of alphanumeric. However, all PIN connections have been declared in the library and correctly connected to the PIC. I use an XC8 compiler.
Here are the connections:
VSS --> GND
VDD --> 5V
VO --> 680Ω resistance
EN --> RD1
RW --> RD6
RS --> RD0
LCD_D4 --> RD2
LCD_D5 --> RD3
LCD_D6 --> RD4
LCD_D7 --> RD5
Anode --> 5V
Cathode --> GND
The global project is a sensor that detects the distance of an object and displays this same distance on the LCD. The fact that the LCD does not display the character compromises the rest of the project because I cannot set up the mathematical calculations if the LCD fails.
1) Library Code : lcd.h (Header Files) This is the code provided by Microchip for the LCD library and I added the PIN-LCD connections:
// single bit for selecting command register or data register
#define instr 0 #define data 1
// These #defines create the pin connections to the LCD in case they
are changed on a future demo board
#define LCD_PORT PORTD
#define LCD_PWR PORTDbits.RD7 // LCD power pin
#define LCD_EN PORTDbits.RD1 // LCD enable
#define LCD_RW PORTDbits.RD6 // LCD read/write line
#define LCD_RS PORTDbits.RD0
#define LCD_D4 PORTDbits.RD2
#define LCD_D5 PORTDbits.RD3
#define LCD_D6 PORTDbits.RD4
#define LCD_D7 PORTDbits.RD5
// LCD register select line
#define NB_LINES 2 // Number of display lines
#define NB_COL 16 // Number of
characters per line
2) Library Code 2 : lcd.c (Source Files) Contains the commands related to the LCD
3) Main Code : main.c (Source Files)
#include "mcc_generated_files/mcc.h"
#include "lcd.h"
#define _XTAL_FREQ 4000000
void main(void)
{
// initialize the device
SYSTEM_Initialize();
// initialize LCD
LCD_Initialize();
LCDGoto(4, 1); // go to column 4, row 1
LCDPutChar("test1");
LCDGoto(3, 2); // go to column 3, row 2
LCDPutStr("test2");
while (1)
{
}
}

#AfricaOMM,
It would appear that your code may be based on code from this link.
Because you posted only fragments it is impossible to determine just how bad the code you are trying to work from is.
The code at link I found has a Microchip copyright but it is of poor quality with bugs that will cause you several problems.
You would benefit in the long run by sorting out this mess on your own.
My best advise is to put LEDs on the signal lines that connect to your LCD module and verify that your PIC16F1937 sets each line to the correct state when the initialization code runs.
I suspect you have errors in wiring along with errors in your code.

Problem solved!
The problem was related to the library.
The library that Microchip provides is full of malfunctions, so when executing commands, the PIC do not receive the supposed informations it should receive, that's why the LCD shows random characters.
I suggest you use the library developed by electrosome : I confirm that it is 100% operational, thanks to them!
Another thing: to solve the contrast problem, it will ideally be necessary to connect the VO port of the LCD to a potentiometer.

When we send a msg on LCD it shows funny characters or some weird symbols because the hardware requires some time to get refreshed. You can try to give some sleep time.after this line
LCDPutStr("test2"). Put above sleep time
LCD.sleep(5)
It worked in my case.

When we send a msg on LCD it shows funny characters or some weird symbols because the hardware requires some time to get refreshed. You can try to give some sleep time.after this line
LCDPutStr("test2"). Put above sleep time
LCD.sleep(5)
It worked in my case. It worked in my case.

Related

Arduino Ultrasonic Distance Sensor with Passive Buzzer to achieve different tones

I have an Ultrasonic Distance Sensor with Passive Buzzer. The passive buzzer was set up with different tones. The buzzer will keep playing until the Ultrasonic Distance Sensor detect any obstruction items. However, the Arduino couldn't compile the code. it displays the error:
exit status 1
Error compiling for board Arduino/Genuino Uno.
Here is the full error message:
Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno"
Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_7'
libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I could locate the function timer0_pin_port in Tone.cpp.o. But I couldn't find the same function in NewPing.cpp.o.
Because of the space limit, I counldn't post the NewPing.cpp.o here. You can download the NewPing.cpp.o here: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
Tone.cpp.o is the original document in the library.
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 10 // Maximum distance we want to ping for (in centimeters).
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
pinMode(2,OUTPUT);
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
if (sonar.ping_cm() == 0)
tone(2,4000);
else
tone(2,0);
}
Expected: The Buzzer will stop playing when the DIstance sensor detects any items. You have to use tone method to support different Tones. Or any similar functions that can support different tones.
From what I understand that the Tone and the NewPing library have a conflicting use of the same interrupt __vector_7. NewPing is known to have conflicting issues, I would suggest you use the original ping in Arduino. Here's a comprehensive example for it.
If you're certain that you're not using the ping_timer() method then in the NewPing.h file make TIMER_ENABLED to false.
Here's a link which talks about Multiple Definition of "__vector_7" Error further.
Here's the thread of a similar problem on the arduino forum.

STM32 USB VCP (Virtual Com Port)

I generated a code for "stm32f103c8t6" with CubeMX for USB VCP, when I add "CDC_Transmit_FS" command to send data, the port isn't recognized by windows10!
what should I do? Here is the code which is compiled without error:
#include "stm32f1xx_hal.h"
#include "usb_device.h"
#include "usbd_cdc_if.h"
int main(void)
{
uint8_t Text[] = "Hello\r\n";
while (1)
{
CDC_Transmit_FS(Text,6); /*when commented the port is recognized*/
HAL_Delay(1000);
}
}
There are three things you need to check in my experience:
startup_stm32f405xx.s --> Increase the Heap size. I use heap size 800 and stack size 800 as well.
usbd_cdc_if.c --> APP_RX_DATA_SIZE 64 and APP_TX_DATA_SIZE 64
usbd_cdc_if.c --> add below code to the CDC_Control_FS() function
Code:
case CDC_SET_LINE_CODING:
tempbuf[0]=pbuf[0];
tempbuf[1]=pbuf[1];
tempbuf[2]=pbuf[2];
tempbuf[3]=pbuf[3];
tempbuf[4]=pbuf[4];
tempbuf[5]=pbuf[5];
tempbuf[6]=pbuf[6];
break;
case CDC_GET_LINE_CODING:
pbuf[0]=tempbuf[0];
pbuf[1]=tempbuf[1];
pbuf[2]=tempbuf[2];
pbuf[3]=tempbuf[3];
pbuf[4]=tempbuf[4];
pbuf[5]=tempbuf[5];
pbuf[6]=tempbuf[6];
break;
and define the uint8_t tempbuf[7]; in the user private_variables section.
Without the increased heap size, Windows does not react at all.
Without the point 3, Windows will send the baud rate information and then read the baud rate, expecting to get back the same values. Since you do not return any values, the virtual com port remains as driver-not-loaded.
If you do all of that, the Windows 10 out-of-the-box VCP driver can be used. No need to install the very old ST VCP driver on your system.
PS: I read somewhere turning on VSense makes problems, too. Don't know, I have not configured it and all works like a charm.
Put delay before CDC_Transmit_FS call - it will wait for the initiatialization. Your code should be like this
int main(void)
{
uint8_t Text[] = "Hello\r\n";
HAL_Delay(1000);
while (1)
{
CDC_Transmit_FS(Text,6); /*when commented the port is recognized*/
HAL_Delay(1000);
}
}
I had similar issue. I couldn't connect to a port and the port appears as just "virtual com port". I added while loop to wait for USBD_OK from CDC_Transmit_FS. Then it stars work even with out it or a delay after init function. I am not sure what the issue was.
while(CDC_Transmit_FS((uint8_t*)txBuf, strlen(txBuf))!=USBD_OK)
{
}
you may have to install driver to get device recognized as com port
you can get it from st site
if not installed the device is listed with question or exclamation mark on device manager
note that you cannot send until device get connected to host!
not sure that CubeMX CDC_Transmit_FS is checking for this
also instead of delay to resend you shall check the CDC class data "TXSstate"
is 0 mean tx is over.
I know it's a bit late, but I stumbled upon this post and it was extremely helpful.
Here is what I needed to do:
do the Line-Coding (I think only necessary on Windows-Systems)
increase Heap (Stack was left at default 0x200)
Here is what wasn't necessary for me (on a STM32F405RGT6 Chip):
change APP_RX_DATA_SIZE / APP_TX_DATA_SIZE (left it at 2048)
add a delay befor running CDC_Tranmit_FS()
Also some things to consider that happened to me in the past:
be sure to use a USB-Cable with data lines (most charging-cables don't have them)
double check the traces/connections if you use a custom board

SAM4S initialization in baby steps

This question may be so obvious it is stupid but I am failing to come up with an answer for it.
I am trying to make a simple makefile project for the sam4s xplained board from Atmel.
I am new to ARM and am feeling a bit lost in how to get stuff to work. Here is what I do trying to get the LEDs to work:
/* Enable clock for PIOC. */
PMC->PMC_WPMR = PMC_WPMR_WPKEY_PASSWD;
PMC->PMC_PCER0 = PMC_PCER0_PID13; /* PIOC clock enable. */
/* Enable output for LED. */
PIOC->PIO_WPMR = PIO_WPMR_WPKEY_PASSWD; /* Enable writing to registers. */
PIOC->PIO_PER = PIO_PER_P10 | PIO_PER_P17; /* Enable pio 10, 17. */
PIOC->PIO_OER = PIO_OER_P10 | PIO_OER_P17; /* Set pio10 and 17 as output. */
PIOC->PIO_SODR = PIO_SODR_P10; /* Set pio10. */
PIOC->PIO_CODR = PIO_CODR_P17; /* Clear pio17 . */
But absolutely nothing happens. Am I missing something?
There should be user LEDs at PIOC 10 and 17.
Board schematics:
http://www.atmel.com/webdoc/sam4s16xplained/sam4s16xplained.boardScematics.section_ggo_tyg_xf.html
The problem was not in the code but in Atmel's tools used to program the board. I had been using SAM-BA In-system Programmer to program the board but for some reason it failed to change the contents of the flash. Even setting a single manually in the memory view fails.
I instead tried Seggers JLink software and did the following steps:
Update the JLink driver on the board using Atmel Studio 6 (this step requires windows).
Downloaded the J-Link software package for Linux from Segger: https://www.segger.com/jlink-software.html.
Using JLinkExe to program the board, like so:
Make sure JP25 is disconnected - only needed for sam-ba.
Connect via usb with the jtag connector.
Start JLinkExe
In the JLink terminal do:
JLink> device at91sam4s16c
JLink> loadbin <target.bin>, 0x400000
Sometimes I need to reset the board before it works after programming it. Using the Segger tools debugging also works now. Start gdb server with JLinkGDBServer and connect with arm-none-eabi-gdb using:
(gdb) target remote :2331
(gdb) file <target.elf>

Generation of RTE_Components.h

I'm working with MDK-Pro and the File System library.
In my application, I require an SPI interface to the SD card. I've managed to setup the project properly, except that in the RTE_Components.h file that Keil generates the line #define RTE_Drivers_MCI0 which subsequently triggers a preprocessor error ("SDIO not configured in RTE_Device.h").
Although I can manually comment out this line in RTE_Components.h, every so often Keil updates this file and I get the above problem. Does anyone know what exactly generates this file, and how I can stop it from adding the SDIO-related definitions into the project?
The RTE_Components.h is not supposed to be modified and will always be automatically generated. That the stack tries to connect via MCI interface is related to your configuration made in the "FS_Config_MC_0.h".
// <o>Connect to hardware via Driver_MCI# <0-255>
// <i>Select driver control block for hardware interface
#define MC0_MCI_DRIVER 0
// <o>Connect to hardware via Driver_SPI# <0-255>
// <i>Select driver control block for hardware interface when in SPI mode
#define MC0_SPI_DRIVER 0
// <o>Memory Card Interface Mode <0=>Native <1=>SPI
// <i>Native uses a SD Bus with up to 8 data lines, CLK, and CMD
// <i>SPI uses 2 data lines (MOSI and MISO), SCLK and CS
// <i>When using SPI both Driver_SPI# and Driver_MCI# must be specified
// <i>since the MCI driver provides the control interface lines.
#define MC0_SPI 1

Program halts while sending byte to USB-to-Prallel (D-Sub 25pins) port

I have an USB to 25-pin parallel port cable. I connected it to laptop and get a port at /dev/usb/lp0, then I connect pin1/pin25 of parallel port with +/- LED it lights.
Now I move +pin of LED to pin 2 of parallel port, and try to send byte to port , it should light up but it doesn't. following is my c code in linux.
#include<stdlib.h>
#include<stdio.h>
#include<sys/io.h>
void main(void)
{
int port=0x378;
outb(0xff,port);
outb(0x01,port+2);
sleep(1);
outb(0x00,port+2);
printf("‌​End");
}
this is my complete program, I also checked it with port=0x3bc but did not work. Even I checked strobe pin 1 by connecting + of LED, it alsways lights but does not go low. May be there is problem with port address.
for /dev/usb/lp0 I also used command line command like $echo $'\xFF' > /dev/usb/lp0 I observed that it does something but does not light up the LED. When I connect LED with pin2 and 25 as + and -. I can see a very little light in side the LED in the beginning but when I run above command that very tiny light disappears but LED does not glow high like it does when I connect it with strobe pin. Also I can only execute above command only two times. Third and later times I thing command does not work while it seems halted.
Can any one help why it halts or how can I get LED switch on/off on data pins? Thanks

Resources