Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:11:03+00:00 2026-06-11T05:11:03+00:00

I am trying to post twitter updates from a sensor interfaced with an Arduino.

  • 0

I am trying to post twitter updates from a sensor interfaced with an Arduino. The Adruino loop has a 1s delay between reading sensor voltages. The Python code has a 1 hour delay between Twitter updates.

It seems that the Python script actually interupts the Arduino loop until it reads a new line on the serial port. Is this correct?

For example, despite the Arduino program running on a loop for 1 hour, it will only show a millis() counter value of 1001, after 2 hours it will show 2002. Without the Python script running and observing the serial monitor only, the Arduino code counts milliseconds as expected.

This wouldn’t normally be a problem, but if you wanted, for example, to simultaneously run a data logger with millis() running continuously at a high acquisition rate it will be an issue. It’s difficult to know what’s going on since the serial monitor can’t share the same port as the Python program.

Here’s a sample of the Arduino code

void loop() {
    unsigned long ms=millis();
    // read the input on analog pin 1:
    int sensorValue = analogRead(A1);
    float Temp = sensorValue * Vref * (100.0/1023.0); 
    // print out the value you read:
    Serial.print(Temp); 
    Serial.print(" degC");
    Serial.print(" , ");
    Serial.print(ms);
    Serial.println(" milliseconds");
    delay(1000);        // delay in miliseconds between reads for stability
}

And here’s the section of the Python code in question:

arduino = serial.Serial('COM6', 9600)

while 1:  ##Infinite Loop
    status = arduino.readline() ##Wait for new line to come across Serial
    api.PostUpdate(status) ##Post message to Twitter
    time.sleep(3600) ##Wait 3600 seconds
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:11:05+00:00Added an answer on June 11, 2026 at 5:11 am

    Serial.write (and any functions that depend on it, like Serial.print) will block if the output buffer is full. The output buffer can only be drained if the other end (i.e. your Python script or the Serial Monitor) reads from the port.

    Serial Monitor constantly reads the serial port output, so the buffer doesn’t fill up. However, since your Python script reads only a single line of output each hour, the buffer is persistently full. Because the serial port is buffered, every hour, you read the next second of output.

    What’s happening here is that your Arduino code runs, say, 10 loops and writes 10 lines before its buffer fills. Your Python code will read the 10 lines, once per hour. After 10 hours, the newer lines that the Arduino has been putting in the buffer will have different timestamps.

    The solution, then, is to either send hourly updates from the Arduino (letting arduino.readline block for an hour in Python) or read updates constantly (every second) from Python and firing your Twitter updates every hour (e.g. use two threads, one to read and update the temperature, the other to post updates every hour using the newest local data).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to autopost an EasyBlog blog post from my own component to Twitter.
I'm trying to make a simple way to post a tweet to twitter, nothing
Trying to post a screenshot in a tweet from within my app.. so far
I'm trying to POST a PayPal or GoogleCheckout buy now button from the code
I’ve been trying to post geolocation-targeted status updates on a Page through the Graph
I am trying to post a url to twitter but the url is user
I am trying to convert the twitter post dates into datetime objects but for
I'm trying to use Twitter's Oauth Single Token for posting from a rails app
Update mysql with $_POST data from while loop I'm trying to get this round
I am trying to render a twitter post that contains unicode (generated aparently with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.