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

  • Home
  • SEARCH
  • 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 8436037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:04:53+00:00 2026-06-10T07:04:53+00:00

I am new to Python and programming in general. I am in the process

  • 0

I am new to Python and programming in general.
I am in the process of making a remote control for Spotify using an Arduino and python.
Whenever a button is pressed on the Arduino, a single character is sent via serial. There is a python script listening for this character and based on what the character is it executes a command. The problem that I am having is that the spotify.playpause() works every time its respective button is pressed, but all the other commands require multiple button presses. I am sure it is not an issue with the Arduino because I have confirmed via multiple serial monitors that the character is being sent correctly, so I believe that it is an issue with the Python loop.

EDIT: Just adding more information, it seems that different combinations of serial.read() or serial.readline on the python side and Serial.print or Serial.println on the Arduino side have no effect on the issue

TL;DR The loop doesn’t fully execute, what’s wrong with it.

Here is the code:

import serial
from pytify import Spotify
spotify = Spotify()
connected = False

ser = serial.Serial("COM3", 57600)

while not connected:
    serin = ser.read()
    connected = True

while True:
    if ser.read() == '0':
         spotify.playpause()
    elif ser.read() == '1':
        spotify.volumeUp()
    elif ser.read() == '2':
        spotify.volumeDown()
    elif ser.read() == '3':
        spotify.previous()
    elif ser.read() == '4':
        spotify.next()
    else :
        pass
  • 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-10T07:04:54+00:00Added an answer on June 10, 2026 at 7:04 am

    Your problem is that you keep calling ser.read for each if/elif case, so you are discarding the value each time your comparison fails. You need to call ser.read only once, then compare that result using a local var, like this:

    c = ser.read()
    
    if c == '0':
       spotify.playpause()
    elif c == '1':
       spotify.volumeUp()
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to python (and programming in general) and am making a database/register
Brand new to Python (and programming in general), if this is simple and/or answered
I'm pretty new to Python and programming in general, and I was wondering if
I'm new to Python and to programming in general. I've installed BioPython in hopes
I'm new to Python and am starting to teach myself GUI programming (hopefully) using
New to Python and programming in general. I want to install a module from
I'm very new to Python and multithreaded programming in general. Basically, I have a
I am new to Python, and programming in general. While I think this question
I'm new to Python and programming in general (a couple of weeks at most).
I'm fairly new to Python and programming in general. I have done a few

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.