I am working on trying to get either twitter or a personal email to display on an lcd 16x2 connected to the internet by an ethernet shield and an arduino uno (r3). The assignment in to modify existing code to get it to work the way we want. I have found various codes but I have very limited knowledge when it comes to coding ( my class did not focus to much behind the coding of the arduinos but how it interacts circuit wise) I am currently looking at two possible codes, one is adafruit twitter thermal printer (Introduction | Internet of Things Printer | Adafruit Learning System) and modify it to display instead of printing. Another is email is email manager that will display email as it arrives (My Open Source Projects: Arduino Email Manager - Part 2 - The Preprocessor)(My Open Source Projects: Arduino Email Manager - Part 3 - Arduino Code) Linked are the original code.
Below is my attempts so far ( I haven't completed it yet) at modifying. I would really appreciate any help, I am having a hard time trying to find the right places to modify the codes. I am not sure if I am heading in the right direction.
Below is my attempts so far
There is nothing below.
Sorry having trouble with posting code
I attached a pdf file of my code because it was not letting me display it. sorry
code for project .pdf (65.8 KB)
code for project .pdf (65.8 KB)
I attached a pdf file of my code because it was not letting me display it. sorry
Maybe that's because you were not using the "#" CODE TAGS button in the second row of the toolbar just to the left of the QUOTE button.
I did try using it but its says that I'm going over the maximum allowed number of characters.
Ok, then you have to attach it as you did.
I forgot to mention that the display i am using the 16x2 is the one that is included with the arduino starter kit.
I found a better code online that someone used to display twitter feed on the arduino using the ethernet shield. http://varut.net/twitter-reader/ It looks pretty good but I run into a continuous stream of connecting to server on the serial monitor in the arduino IDE with no change. Here is the code I modified (basically lcd settings ) ** Note that I did add the mac address from the ethernet shield in the code for purposes of displaying the code I removed my mac address**
/*
Original Twitter code created
by Tom Igoe
This code is in the public domain.
This code has been edited to make twitter scrolling feed by Varut Rintanalert. However, I am still finding some problem with the LCD memory
*/
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE };
IPAddress ip(192,168,1,35);
LiquidCrystal lcd(9, 8, 6, 5, 3, 2);
// initialize the library instance:
EthernetClient client;
const unsigned long requestInterval = 30000; // delay between requests
char serverName[] = "api.twitter.com"; // twitter URL
boolean requested; // whether you've made a request since connecting
unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds
String currentLine = ""; // string to hold the text from server
String tweet = ""; // string to hold the tweet
boolean readingTweet = false; // if you're currently reading the tweet
int lcd_start = 0; // Position of the text
int text_len = 0; // limit on LCD
int lcd_limit = 0; // the limit of lcd
int channel = 0; //Channel 0 = CNN 1 = Wired 2 = BBC
void setup() {
// reserve space for the strings:
currentLine.reserve(256);
tweet.reserve(150);
lcd.begin(16, 2);
lcd.print("Starting");
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// attempt a DHCP connection:
Serial.println("Attempting to get an IP address using DHCP:");
delay(100);
lcd.print(".");
if (!Ethernet.begin(mac)) {
// if DHCP fails, start with a hard-coded address:
Serial.println("failed to get an IP address using DHCP, trying manually");
Ethernet.begin(mac, ip);
}
Serial.print("My address:");
Serial.println(Ethernet.localIP());
// connect to Twitter:
lcd.print(".");
delay(100);
connectToServer();
}
void loop()
{
if (client.connected()) {
if (client.available()) {
// read incoming bytes:
char inChar = client.read();
// add incoming byte to end of line:
currentLine += inChar;
// if you get a newline, clear the line:
if (inChar == '\n') {
currentLine = "";
}
// if the current line ends with <text>, it will
// be followed by the tweet:
if ( currentLine.endsWith("<text>")) {
// tweet is beginning. Clear the tweet string:
readingTweet = true;
tweet = "";
}
// if you're currently reading the bytes of a tweet,
// add them to the tweet String:
if (readingTweet) {
if (inChar != '<') {
tweet += inChar;
}
else {
// if you got a "<" character,
// you've reached the end of the tweet:
readingTweet = false;
Serial.println(tweet);
char text[tweet.length()];
tweet.toCharArray(text, tweet.length()+1);
text_len = (sizeof(text)/sizeof(char))-1;
lcd_limit = text_len - 16;
if(lcd_limit <= 0){
Serial.println("The text is less than 16 char");
lcd_limit = (sizeof(text)/sizeof(char))-1;
}
else{
Serial.print("the text lenght is ");
Serial.println(text_len);
}
//begin writing to LCD
// close the connection to the server:
Serial.println("Stopping Client");
client.stop();
lcd.clear();
// This part is for the channel name. Beware that your channel should add 1 extra
// this is because the variable channel gets incremented at the end of each loop
if(channel == 1){
lcd.setCursor(0,1);
lcd.print("CNN");
}else if(channel == 2){
lcd.setCursor(0,1);
lcd.print("WIRED");
}else if(channel == 3){
lcd.setCursor(0,1);
lcd.print("BBCBNews");
}else if(channel == 0){
lcd.setCursor(0,1);
lcd.print("WIRED UK");
}
lcd.setCursor(0,0);
Serial.print("Here is the text ");
Serial.println(text);
//Writing to LCD
int counterText = 0; // make new counter this is use to keep track of how much turn it has been run
int text_lenreverse = (text_len*-1)+14;
Serial.print("Text len reverse");
Serial.println(text_lenreverse);
//running the loop until the tex
for(int textPosi = 15; textPosi>text_lenreverse; textPosi--){
//sending the 16 char
for(int thisChar = 0; thisChar < 16; thisChar++)
{
// exit loop and uses the next loop
if(textPosi > 0){
lcd.setCursor(textPosi+thisChar,0);
lcd.print(text[thisChar]);
}else {
lcd.setCursor(thisChar,0);
lcd.print(text[thisChar+counterText-15]);
}
}
//print if and only if the text position is less than zero
//loop printing the next rest
counterText++; // counting how many packet has been sent
delay(150);
}//while(textPosition > 16);
Serial.println("Exit loop");
}
}
}
}
else if (millis() - lastAttemptTime > requestInterval) {
// if you're not connected, and two minutes have passed since
// your last connection, then attempt to connect again:
connectToServer();
}
}
void connectToServer() {
// attempt to connect, and wait a millisecond:
Serial.println("connecting to server...");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Connecting");
if (client.connect(serverName, 80)) {
Serial.println("making HTTP request...");
lcd.clear();
lcd.setCursor(0,0);
if(channel == 0){
lcd.print("Requesting");
lcd.setCursor(0,1);
lcd.print("CNN");
client.println("GET /1/statuses/user_timeline.xml?screen_name=cnn&count=1 HTTP/1.1");
channel++;
/* }else if(channel == 1){
lcd.print("Requesting");
lcd.setCursor(0,1);
lcd.print("WIRED");
client.println("GET /1/statuses/user_timeline.xml?screen_name=wired&count=1 HTTP/1.1");
channel++;
}else if(channel == 2){
lcd.print("Requesting");
lcd.setCursor(0,1);
lcd.print("BBC Breaking News");
client.println("GET /1/statuses/user_timeline.xml?screen_name=BBCBreaking&count=1 HTTP/1.1");
channel++;
}else if(channel == 3){
lcd.print("Requesting");
lcd.setCursor(0,1);
lcd.print("Wired UK");
client.println("GET /1/statuses/user_timeline.xml?screen_name=WiredUK&count=1 HTTP/1.1");
channel=0; */
}else if (channel == 4){
lcd.print("Requesting");
lcd.setCursor(0,1);
lcd.print("Bikeykay");
client.println("Get /1/statuses/user_timeline.xml?screen_name=bikeykay&count=1 HTTP/1.1");
}
client.println("HOST: api.twitter.com");
client.println();
}
// note the time of this connect attempt:
lastAttemptTime = millis();
}
I managed to fix the ip address connection error I connected it directly to my wifi router. Before I was connecting it to my macbook's ethernet port. Now I am having trouble with accessing the data with the twitter api information. I've changed the version to reflect the latest being 1.1 but it tries connecting to the twitter information and just resets and tries to connecting to the server again with no success. Can anyone help me fix that?