Introduction: 20 X 4 Liquid crystal display News Rss Feed With Adruino/python

This is an updated version of this instructable : https://WWW.instructables.com/id/Wiring-up-the-LCD-... All the credits goes to the original author. A fewer key updated features for the new project and code:

  1. 20 x 4 LCD with I2C.
  2. Python 3 instead of 2
  3. On the job news program links
  4. Key input choice added. Please note the python program need to be open in order to use the key input.

Thanks and enjoy.

Step 1: The Adruino Encrypt: (this Needed to Be Started Earlier Python)

<p>// This code is for the Arduino RSS feed project, by Fritter<br>// Read the comment lines to figure out how it works //I reedited the encrypt for the 20 x 4 LCD I2C display aside trial and error. it sooner or later worked.  //A batch of patience for frustrations. Incremental changes to understant the behavior and logic or the computer code versus completely different approaches. //postulate to use newsfeed.py, start adruino first.</p><p>// include the library code:. conducting wire, LiquidCrystal. LiquidCrystal_I2C</p><p>#include <Electrify.h> </p><p>#admit <LiquidCrystal.h></p><p>#include  <LiquidCrystal_I2C.h></p><p> int startstring = 0;     // credit of beginning of new string int charcount = 0;     // keeps caterpillar tread of total chars along screen         LiquidCrystal_I2C lcd2(0x27,20,4); // LiquidCrystal_I2C lcd(i2c_addr, nut, rw, rs, d4, d5, d6, d7, BACKLIGHT_PIN, POSITIVE); int CodeIn;// old on all serial reads <br></p><p>void setup(){</p><p>lcd2.begin(); lcd2.clear(); lcd2.backlight(); lcd2.setCursor(0,0); lcd2.print("TOP TEN NEWS"); delay(1000); lcd2.clear();</p><p> Order.get down(9600);  }</p><p>void loop() {         char incomingByte = 0;   // for incoming sequent data                  if (Serial.available() > 0) {        // Check for incoming Sequential Data                                    incomingByte = Music.read();                  if ((incomingByte == '~') &A;&adenosine monophosphate; (startstring == 1)){            // Check for the last '~' to end the printing of serial data                                              startstring = 0;                                                                  // Lot the printing process to off                    delay(4000);                                                                     // Time lag 4 seconds for referee to read                    lcd2.clear();                                                                         // Wipe the screen                    charcount = 0;                                                                   // reset the character count to 0                    lcd2.setCursor(0,0);                                                          // reset the cursor to 0,0                  }                  if (startstring == 1){                                                             // check if the drawstring has begun if prime '~' has been read                    if (charcount <= 129){                       if (charcount == 20){                      lcd2.setCursor(0,1);                    }                      if (charcount == 40){                      lcd2.setCursor(0,2);                    }                      if (charcount == 60){                      lcd2.setCursor(0,3);                      }                      if (charcount == 80){                                                                             delay(2500);                      lcd2.unobstructed();                                                                        // clear the screen                      lcd2.setCursor(0,0);                       charcount = 1;                        }                      lcd2.print(incomingByte);                                                // Print the flow byte in the serial                      charcount = charcount++;                                             // Increment the charcount by 1 yes I know IT's awkward                      }                  }                                                                              // hard pointer to 0,0                                     // continue printing data                                                                                    // set charcount back to 1                                                       if (incomingByte == '~'){                                                    // Check if byte is marker ~ to start the printing                                       startstring = 1;                                                                  // start printing                  }          }                                    delay(10);                                                                            // 10ms delay for stability              }</p>

Step 2: Python 3 Code

#import library to do hypertext transfer protocol requests:
import urllib.call for #import pyserial Library import serial #importation time depository library for delays import time
#import xml parser named minidom: from xml.dom.minidom import parseString
#Initialize the Serial connection in COM3 operating theater whatever interface your arduino uses at 9600 baud rate ser = successive.Music("\\.\COM7", 9600) i = 1 #delay for stability piece connection is achieved time.sleep(5) while i == 1:      newsSource = input("what Tidings Source would you look-alike to use? 1= Reuters; 2= BBC; 3 = Fox")      #download the rss file feel free to put your own rss universal resource locator in here      if newsSource == '1':           HTTP = 'hypertext transfer protocol://feeds.reuters.com/reuters/topNews'           print ('1aaa')               elif newsSource == '2':           http = 'http://feeds.bbci.co.uk/intelligence/world/asia/rss.xml'           photographic print ('2bbb')      elif newsSource == '3':           http = 'hypertext transfer protocol://feeds.foxnews.com/foxnews/in style'           print ('3ccc')      elif newsSource == '':           time.sleep(30)           http = 'http://feeds.foxnews.com/foxnews/latest'      file = urllib.request.urlopen(hypertext transfer protocol)      #convert to drawstring      information = file.read() #close the file      file out.close() #parse the xml from the string      dom = parseString(data) #think back the first xml tag (information) that the parser finds with name tagName alteration tags to get different information      xmlTag = dom.getElementsByTagName('title')[2].toxml() # the [2] indicates the 3rd title tag information technology finds will make up parsed, tally starts at 0 #strip off the tag (information  --->   information) xmlData=xmlTag.replace(' </p><p>','').replace('<!--[CDATA[','').replace(']]-->','')</p>            
              ser.write(b'~') #split the string into individual words      nums = xmlData.separate(' ') #loop until complete actor's line in string have been printed      for num in nums: #spell 1 word           ser.write out(num.encode('UTF-8')) # write 1 space           ser.write(b' ') # THE DELAY IS Requisite. It prevents overflow of the arduino buffer.           time.eternal rest(1)           xmlTag = dom.getElementsByTagName('title')[3].toxml()      # the [2] indicates the 3rd title tag it finds leave be parsed, counting starts at 0      #reave off the tag (data  --->   data) <atomic number 35><p>xmlData=xmlTag.replace('</p> <p>','').replace('<!--[CDATA[','').replace(']]--> ','')</p>      xmlData=xmlTag.supervene upon('            
','').replace('','')      #write the marker ~ to serial      ser.write(b'~')      #split the strand into individual words      nums = xmlData.split(' ')      #loop until all words in drawstring take been printed      for num in nums:           #write 1 word           ser.write(num.encode('UTF-8'))           # compose 1 space           ser.write(b' ')           # THE Check IS NECESSARY. It prevents overflow of the arduino buffer.           time.sleep(1)      xmlTag = dom.getElementsByTagName('title')[4].toxml()      # the [2] indicates the 3rd title tag it finds will be parsed, counting starts at 0      #peel unsatisfactory the tag (information  --->   information)      xmlData=xmlTag.replace('
','').replace('
','')
              #write the marker ~ to serial      ser.write(b'~')      #split the string into individual wrangle      nums = xmlData.split(' ')      #coil until all words in string have been printed      for num in nums:           #write 1 word           ser.write(num.encode('UTF-8'))           # write 1 blank           ser.write(b' ')           # THE DELAY IS NECESSARY. Information technology prevents overflow of the arduino buffer.           clip.sleep(1)      xmlTag = dom.getElementsByTagName('title')[5].toxml()      # the [2] indicates the 3rd title tag it finds will be parsed, reckoning starts at 0      #strip off the tag (information  --->   data)      xmlData=xmlTag.replace('
','').substitute('
','')
              #write the marking ~ to ordination      ser.write(b'~')      #split the cosmic string into individual words      nums = xmlData.split(' ')      #loop until all dustup in string birth been printed      for num in nums:           #write 1 word           ser.pen(num.inscribe('UTF-8'))           # publish 1 space           ser.write(b' ')           # THE Check IS NECESSARY. It prevents overflow of the arduino pilo.           clock.eternal sleep(1)      xmlTag = dom.getElementsByTagName('title')[6].toxml()      # the [2] indicates the 3rd entitle tag information technology finds will be parsed, counting starts at 0      #rifle off the tag (information  --->   data)   xmlData=xmlTag.replace('
','').replace('
','')
              #write the marker ~ to serial      ser.write(b'~')      #split the drawing string into individual words      nums = xmlData.split(' ')      #loop topology until all words in string have been printed      for num in nums:           #write 1 word           ser.write(num.encode('UTF-8'))           # write out 1 space           ser.publish(b' ')           # THE Check IS NECESSARY. It prevents overflow of the arduino buffer.           time.sopor(1)      xmlTag = dom.getElementsByTagName('title')[7].toxml()      # the [2] indicates the 3rd title tag IT finds will be parsed, counting starts at 0      #strip off the rag (data  --->   information)      xmlData=xmlTag.replace('
','').replace('
','')
              #write the marker ~ to sequent      ser.write(b'~')      #split the string into individual run-in      nums = xmlData.cut(' ')      #loop until all words in string have been printed      for num in nums:           #write 1 word           ser.write(num.encode('UTF-8'))           # write 1 quad           ser.write(b' ')           # THE DELAY IS NECESSARY. It prevents overflow of the arduino buffer.           clock time.sleep(1)      xmlTag = dom.getElementsByTagName('title')[8].toxml()      # the [2] indicates the 3rd title chase after it finds leave be parsed, counting starts at 0      #strip hit the tag (data  --->   data)      xmlData=xmlTag.replace('            
','').replace('','')      #write the marker ~ to serial      ser.publish(b'~')      #split the string into someone words      nums = xmlData.disconnected(' ')      #loop until all actor's line in string have been printed      for num in nums:           #write 1 word           ser.write(num.encode('UTF-8'))           # publish 1 space           ser.write(b' ')           # THE Holdup IS NECESSARY. It prevents overflow of the arduino buffer.           time.eternal sleep(1)      xmlTag = dom.getElementsByTagName('title')[9].toxml()      # the [2] indicates the 3rd title mark it finds will comprise parsed, tally starts at 0      #strip off the tag (data  --->   data)      xmlData=xmlTag.replace('
','').replace('
','')
              #indite the marker ~ to serial      ser.pen(b'~')      #split the string into individual words      nums = xmlData.split(' ')      #coil until all words in string up have been printed      for num in nums:           #write 1 word           ser.indite(num.encode('UTF-8'))           # compose 1 space           ser.publish(b' ')           # THE Stay IS NECESSARY. It prevents overflow of the arduino buffer.           time.sleep(1)      xmlTag = dom.getElementsByTagName('title')[10].toxml()      # the [2] indicates the 3rd title tag it finds will be parsed, counting starts at 0      #strip off the trail (data  --->   data)      xmlData=xmlTag.put back('
','').replace('
','')
              #drop a line the marking ~ to serial      ser.write(b'~')      #burst the string into individualistic words      nums = xmlData.stock split(' ')      #loop until complete words in string have been written      for num in nums:           #write 1 word           ser.write(num.encode('UTF-8'))           # write 1 space           ser.publish(b' ')           # THE DELAY IS NECESSARY. It prevents overflow of the arduino buffer storage.           time.slumber(1)      xmlTag = dom.getElementsByTagName('title')[11].toxml()      # the [2] indicates the 3rd rubric tag information technology finds will be parsed, counting starts at 0      #strip off the tag (data  --->   data)      xmlData=xmlTag.supercede('
','').replace('
','')
              #write the marker ~ to serial      ser.pen(b'~')      #split the string into one-on-one words      nums = xmlData.split(' ')      #grommet until all words in string have been written      for num in nums:           #write 1 discussion           ser.write(num.encode('UTF-8'))           # write 1 space           ser.publish(b' ')           # THE DELAY IS NECESSARY. It prevents overflow of the arduino buffer store.           time.sleep(1)
# write ~ to close the string and tell apart arduino information sending is finished      ser.write(b'~') # waitress 2 seconds before rechecking RSS and resending data to Arduino      ser.write(b'~TOP TEN NEWS 1= Reuters; 2= BBC; 3 = Fox')      time.sleep(2)

Be the First to Share

Recommendations

  • Anything Goes Contest 2022

    Anything Goes Contest 2022