Babitha
Posts: 1
Joined: Sat Oct 27, 2018 11:55 am

Error in Web based Notice Board.please Help...

Sat Oct 27, 2018 12:16 pm

Hello Everyone,i am newbie to raspberrypi and python.i am working on "web based notice board".i am following this link https://circuitdigest.com/microcontroll ... spberry-pi .i am using Raspberrypi3 and python3 IDLE.i successfully installed Flask and also changed IP address.my LCD is working is also working fine and i can open the webpage too.here the problem is whenever i open and given some message in textbox(which is in webpage) that message is not displaying on my lcd.it is showing some random charaters.the same characters everytime."6 &7v BEF vW7EvV" what does it mean...?can u please help me with this.the code is given below.or can u please give any other link which is working for web based notice board.thankyou in advance

Code: Select all

from flask import Flask
from flask import render_template, request
import RPi.GPIO as gpio
import os, time
app = Flask(__name__)
RS =18
EN =23
D4 =24
D5 =16
D6 =20
D7 =21
HIGH=1
LOW=0
OUTPUT=1
INPUT=0
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(RS, gpio.OUT)
gpio.setup(EN, gpio.OUT)
gpio.setup(D4, gpio.OUT)
gpio.setup(D5, gpio.OUT)
gpio.setup(D6, gpio.OUT)
gpio.setup(D7, gpio.OUT)
def begin():
  lcdcmd(0x33) 
  lcdcmd(0x32) 
  lcdcmd(0x06)
  lcdcmd(0x0C) 
  lcdcmd(0x28) 
  lcdcmd(0x01) 
  time.sleep(0.0005)
 
def lcdcmd(ch): 
  gpio.output(RS, 0)
  gpio.output(D4, 0)
  gpio.output(D5, 0)
  gpio.output(D6, 0)
  gpio.output(D7, 0)
  if ch&0x10==0x10:
    gpio.output(D4, 1)
  if ch&0x20==0x20:
    gpio.output(D5, 1)
  if ch&0x40==0x40:
    gpio.output(D6, 1)
  if ch&0x80==0x80:
    gpio.output(D7, 1)
  gpio.output(EN, 1)
  time.sleep(0.0005)
  gpio.output(EN, 0)
  # Low bits
  gpio.output(D4, 0)
  gpio.output(D5, 0)
  gpio.output(D6, 0)
  gpio.output(D7, 0)
  if ch&0x01==0x01:
    gpio.output(D4, 1)
  if ch&0x02==0x02:
    gpio.output(D5, 1)
  if ch&0x04==0x04:
    gpio.output(D6, 1)
  if ch&0x08==0x08:
    gpio.output(D7, 1)
  gpio.output(EN, 1)
  time.sleep(0.0005)
  gpio.output(EN, 0)
  
def lcdwrite(ch): 
  gpio.output(RS, 1)
  gpio.output(D4, 0)
  gpio.output(D5, 0)
  gpio.output(D6, 0)
  gpio.output(D7, 0)
  if ch&0x10==0x10:
    gpio.output(D4, 1)
  if ch&0x20==0x20:
    gpio.output(D5, 1)
  if ch&0x40==0x40:
    gpio.output(D6, 1)
  if ch&0x80==0x80:
    gpio.output(D7, 1)
  gpio.output(EN, 1)
  time.sleep(0.0005)
  gpio.output(EN, 0)
  # Low bits
  gpio.output(D4, 0)
  gpio.output(D5, 0)
  gpio.output(D6, 0)
  gpio.output(D7, 0)
  if ch&0x01==0x01:
    gpio.output(D4, 1)
  if ch&0x02==0x02:
    gpio.output(D5, 1)
  if ch&0x04==0x04:
    gpio.output(D6, 1)
  if ch&0x08==0x08:
    gpio.output(D7, 1)
  gpio.output(EN, 1)
  time.sleep(0.0005)
  gpio.output(EN, 0)
 
def lcdprint(Str):
  l=0;
  l=len(Str)
  for i in range(l):
    lcdwrite(ord(Str[i]))
begin()
print("hi")
lcdprint("Circuit Digest")
lcdcmd(0xc0)
lcdprint("Welcomes You")
time.sleep(5)
@app.route("/")
def index():
    return render_template('web.html')
@app.route("/change", methods=['POST'])
def change():
 if request.method == 'POST':
    # Getting the value from the webpage
   data1 = request.form['lcd']
   lcdcmd(0x01)
   lcdprint(data1)
 return render_template('web.html', value=data1)
if __name__ == "__main__":
    app.debug = True
    app.run('192.168.1.9', port=8080,debug=True)

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Error in Web based Notice Board.please Help...

Mon Oct 29, 2018 11:12 am

Is the initial "Circuit Digest" etc displayed ok? If not I would test the lcd behavior by taking your code and stipping all the flask stuff out then just sending simple messages to the lcd to see what I got. I would put prints in at various stages to check what was happening, maybe alter the sleep times a bit. If it's only the web entered text which is corrupted maybe you need to decode/encode the string (That's the kind of thing that python2 swept under the carpet so maybe the origin project was done with python2)

Also a large part of your (copied from the web, I know) code seems to be two functions that are identical apart from one character and which contain a lot of repeated code so it will be hard for you to trace typos etc. They could probably be boiled down to something like (untested)

Code: Select all

def lcdcmd(ch):
  lcdcmd_or_write(ch, 0)

def lcdwrite(ch):
  lcdcmd_or_write(ch, 1)

def lcdcmd_or_write(ch, rs_val):
  D_LIST = [D4, D5, D6, D7]
  gpio.output(RS, rs_val)
  for m in [0x10, 0x01]:
    for i in range(4):
      mask = m << i # will be 0x10,0x20,0x40.. then 0x01,0x02...
      if ch & mask == mask:
        d_bit = 1
      else:
        d_bit = 0
      gpio.output(D_LIST[i], d_bit)
    gpio.output(EN, 1)
    time.sleep(0.0005)
    gpio.output(EN, 0)
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”