element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum The "Ultimate" Raspberry Pi - With analoge stick
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 9 replies
  • Subscribers 706 subscribers
  • Views 1478 views
  • Users 0 members are here
  • raspberry
  • i2c
  • retro
  • adc
  • arduino
Related

The "Ultimate" Raspberry Pi - With analoge stick

thorleif@tjweb.no
thorleif@tjweb.no over 10 years ago

Hello there!

 

I've been struggelign a while now with a handheld console (Retro Game Pi). The tutorial says to use a adapter to make the analoge stick i want to use as a digital 1 and 0 stick. But i really want analoge inputs aswell so i can use it in games which requires an analog stick (Monkey Island on scummvm e.g.).

 

So i started exploring fields i never been on before, i found out using a i2c enabled ADC i could read the values into pyton, using a uinput module to make a joystick move. So i programmed an attiny to read analoge values, pass them on as 2 bytes on i2c into my raspberry pi using python. Somehow i get values around 310 on 1.64 volt and 895 on 3.3v so it dosent seem to work properly (running it on 3.3v).

 

So i give kinda up on what i'm doing and want to ask you guys if you have any tip on how i can get this to work? Both making the joystick analog and digital (dpad function when emulator needs it, or joystick if emulator needs that)z

  • Sign in to reply
  • Cancel
Parents
  • clem57
    clem57 over 10 years ago

    There are two approaches. One you tried using an intermediary process (attiny). Here you need to "scale" the results to say 0-1024 matching 0-3.3v. Your results above is not to bad. The other way is use analog signal and measure the characteristics of the circuit. This article shows how: Conventional Analog: Into Digital - How Joysticks Work | HowStuffWorks . The Pi can handle this case directly and measure time to register a +1. Trick is setting the capacitance to a high enough value but not too high. This affects the speed versus the sensitivity(range of values). I am planing to use this design in the near future.

    Clem

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • thorleif@tjweb.no
    thorleif@tjweb.no over 10 years ago in reply to clem57

    But should i not get 0-1024 by using a 3.3v supply to attiny and to the joystick? jumping VCC to A0 gets 895 on analogread, and jumping ground gives 0. Thought i'd get 1024 on 3.3v since thats the only ref the unit have ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to thorleif@tjweb.no

    The aref voltage affects the range you get. If the voltage at aref is higher than 3.3v, I can see a number lower than 1024 even if the measured voltage is 3.3v. The circuit is a comparator between voltage between aref and measured input to determine the digital number returned.

    Clem

    Edit: You need to measure the actual voltage at the inputs to the ADC.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • thorleif@tjweb.no
    thorleif@tjweb.no over 10 years ago in reply to clem57

    That is correct other than the voltage given to the chip is 3.3V no 5V even close to it. So 3.3 should be the reference on attiny since i power it with that?


    1024 / 5V * 3,3 = 675,84 is not 895 so it could not use 5v as reference

     

    Also it sometimes gives 1024 like.. 5-10 times each 5sec out of a couple of hundreds pr 5sec. I dont understand how it gets 895 instead of 1024. The button sends 1024 but the X and Y axis are 0-895 both of them.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to thorleif@tjweb.no

    Without a schematic and pictures, I cannot correlate what is happening. I do know the theory of what should be.

    Thanks,

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • clem57
    clem57 over 10 years ago in reply to thorleif@tjweb.no

    Without a schematic and pictures, I cannot correlate what is happening. I do know the theory of what should be.

    Thanks,

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • thorleif@tjweb.no
    thorleif@tjweb.no over 10 years ago in reply to clem57

    Found out a problem now. I made a variable (X) increment from 0 to 1024 each time i asked for data via i2c and i see that it loops back to 0 on 895. So its code related not hardware.
    It counts from 0 to 895 then from 0 to 127. Probably something wrong with my i2c byte thingy then image

     

    Arduino: (This increments x from 0 to 1023 and resets it.

          int a = 1024;

          if ( x >= 1024) x = 0;

          if(digitalRead(Z_AXIS)) { a = x++ ; }

          TinyWireS.send( highByte(a) );

          TinyWireS.send( lowByte(a)  );

    Python: This receives the two bytes and adds them to a number i thought image

      Hi = bus.read_byte(address) # Read the High byte of the frame

      Lo = bus.read_byte(address) # Read the Low byte of the frame

      return (Hi << 8) + Lo # Convert to number



    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to thorleif@tjweb.no

    This makes sense. The hardware was so unclear to me as you described it. The facts you claimed was a non sequitur to reality.

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube