Find Status of LED on coffee maker using Arduino? - python

I'm new to the Arduino platform and i'm wondering if it is possible to tell if an LED is on using an arduino input? I'm confused as to if i can check the voltage of one side of the LED in reference to the Arduino's ground? or would i have to check the voltage relative to the other terminal of the LED.
Just a little confused.

This question is probably better asked on electronics.SE, but here goes:
Yes, it is possible, and there are a couple of ways you could do this:
You could hook up a light sensor to your arduino, aim it at the led, and read that. No modification of the coffee maker is needed
You could connect a wire to a coffee maker LED, and connect it to Arduino. But where to connect the wire? To understand this you have to consider how LEDs are usually hooked up: there is the control signal, the LED itself, a current-limiting diode, and ground. The two main options look like this:
Assuming that the control voltage is either +5 or zero volts, and assuming your arduino runs on that (and not 3.3V, for example), in both cases (the one on the left and the one on the right), you want to connect your wire to the point indicated as "control". In the left hand case is "before" the resistor, but in the right hand case it is "before" the LED. You should use your multimeter to confirm your assumptions about the LED circuit, and verify that the connection point indeed is either at +5V and 0v (or whatever your expected voltages are) when the LED is on or off, respectively (if you don't have a multimeter, then this might not be a good project for you)

Related

How to check if a note has been played in a audio file

I am trying to create a application that changes the color of lights depending on what note is played on a musical keyboard, I have got the light changing, but have no clue how to check if the note from the keyboard is the same as a pre recorded sound.
This is a simple diagram
Keyboard from audio interface -> Software -> Changes light color depending on the note
The software is just to check if a note has been played, if so, what note, and return a string for the second half of the software to change the light to.
If you press F# on the keyboard, it would make the lights turn red.

Webots NAO controller sequence not working

I am using the NAO_demo_python controller of the latest version of webots on linux (ubuntu 18) to flash leds and open/close the hands.
However only the last part of the sequences are executed, and not in a single simulation run.
e.g. if i ask to just open the hand and light the leds, after 1 run the lights will be on and after 5 runs of the main while loop it will be opened -reaaallly slowly-. However if i ask lit leds, open hand then close hand unlit leds then the simulation will only close hand and unlit leds.
The code should be working, it is on another person's computer. In case you want it here it is (it's really basic, it's a slight modification of nao-demo-python.py):
def run(self):
while robot.step(self.timeStep) != -1:
self.setAllLedsColor(0xff0000) #red leds on
self.setHandsAngle(0.96) #open hand
#rospy.sleep(5) #originally i am to use webots and nao with ros
print("done") #to check how many runs are made
self.setHandsAngle(0.0) #close hand
self.setAllLedsColor(0x000000) #red leds off
Also, something that may be interesting: if i ask to open close the hand N times and each time print something, all the prints will be printed at once and the simulation time jump from 0:0:0 to 0:0:20 after each main loop run (+20 at each run), else, even if the simulation runs the time doesn't flow, it jumps.
I tried to update my drivers, to take off all shadows and stuff from the simulation, as webots advices. No can do. I couldn't find something on Softbank, i can't find an active forum concerning nao and webots anymore...
I have an i5 9th gen and a GTX1050Ti.
May the problem be that the simulation time isn't 1.0x? but at most 0.05x? (after taking off shadows, effect of lights, all objects, using 1 thread etc, as explained here: https://www.cyberbotics.com/doc/guide/speed-performance)
SUMMARY: Only the last sequence of the controller is executed, and if it's a motion it takes several main loops before being fully executed. Meanwhile the time jumps from 0 to +20s after each main loop run.
May someone help me out to make all the sequence work on simulation please :)
all the prints will be printed at once
Only the last sequence of the controller is executed
It sounds like the setHandsAngle function might be asynchronous (doesn't wait for the hand to move to that point before running the next piece of code)? This could be responsible for at least some of the problems you're experiencing. In this case the rospy.sleep(5) should be replaced with robot.step(5000), so the simulator has time to move the hand before sending the next command.
Thank to your indications, this works:
self.CloseHand = Motion('../../motions/closeHand.motion')
def startMotion(self, motion):
if self.currentlyPlaying: #interrupt current motion
self.currentlyPlaying.stop()
motion.play() #start new motion
self.currentlyPlaying = motion
self.startMotion(self.CloseHand)
while not self.CloseHand.isOver():
robot.step(self.timeStep)
And in the CloseHand.motion :
#WEBOTS_MOTION,V1.0,LPhalanx1,RphalanxN (until 9)
00:00:000,Pose1,0.00,0.00 etc
with 00:00:000 the moment of execution and 0.00 the angle of the hand (phalanx by phalanx).
THANK you very much! I couldn't have realized that without your advice.
The synchronization webots/ros is still unresolved but the issue of my initial question is. Thank you!

One joystick works with pygame and another won't?

I am currently building a robot that I would like to control with a pair of nice joysticks I bought. Up until now I've been using pygame.joystick with no problems at all with my PS4 controller. However the new joysticks have a problem. They output the correct values for like twenty or thirty seconds and function properly, but then they just freeze on a value. I can't think of any reasons they would work fine for a certain amount time and then all of a sudden just freeze.
My code is as simple as:
pygame.init()
leftjoy = pygame.Joystick.joystick(0)
leftjoy.init()
while True:
print(leftjoy.get_axis(0))
pygame.event.pump()
Update:
I tried this same code on Windows instead of raspberry pi and it worked perfectly. I plan on using ssh when controlling the robot so it should work well for that application. But I would still like to know how to fix this problem for testing.
A couple shots in the dark, without access to your hardware...
Since the PS4 controller works, I'm guessing the code and the RasPi are in good health, so the joysticks themselves might be somewhat buggy. The problem could be that the joysticks momentarily disconnect (power issue, faulty cable, just faulty hardware), and upon reconnect are assigned a new address such as 1. I don't recall that being a common problem in RasPi in general, but PyGame might have issues. Here's another post with some code that might help you detect and debug joystick disconnects in software. To much more quickly test that possibility in hardware, intentionally do a momentary disconnect-connect early, while your game is "working" and see if the same result happens.
Finally, maybe the RasPi is polling too quickly and causes the joystick to freeze. To debug this, you could try putting a delay in your loop.

What signal does the front button of a Wii Board send, to be consumed by a Python script?

I am trying to write a daemon which would listen to incoming messages from a Wii Board and translate them into a weight (and send it further to an existing dashboard). This will heavily reuse some existing implementations.
I have the code from the implementation above working fine when pressing the red synchronization button on the Wii Board (it displays my weight). I now would like to use the front button to synchronize (instead of the red one).
The Wii Board is paired and trusted. When starting the program with the address of the Wii Board and pressing the front button, I get a timeout bluetooth.btcommon.BluetoothError: (112, 'Host is down') on
self.receivesocket.connect((address, 0x13))
I get the same result when not pressing anything. Again, pressing the red button works fine.
I was under the impression that the red button is for pairing and not used after that (this is the behaviour of a Wii). The front button would be usd for initiating the connection then.
Is the failing call above expecting something the Wii Board can send via the front button? In other words - can this button replace the red synchronization one and under which conditions?
Note: I am aware that this question is borderline SO-compatible. I put it here because I am looking to write/improve a Python daemon but lack the Bluetooth knowledge. If you feel it is better moved somewhere (SU? RPi?) please let me know.

Monitoring a displays state in python?

How can I tell when Windows is changing a monitors power state?
It seems that, when Windows wants to start the screen saver or turn the monitor off, it will send a WM_SYSCOMMAND to the topmost window with a wParam of SC_SCREENSAVE (to start the screen saver) or a wParam of SC_MONITORPOWER and a lParam of 1 or 2 (to turn the monitor off). This message will then be passed to DefWindowProc, which will actually do the action. So, if your window happens to be the topmost one, you can intercept these events and ignore them (or do anything else you want before passing them to DefWindowProc).
On Windows Vista, there seems to be a more intuitive, and more reliable, way to know the monitor power state. You call RegisterPowerSettingNotification to tell the system to send your window a WM_POWERBROADCAST message with a wParam of PBT_POWERSETTINGCHANGE and a lParam pointing to a POWERBROADCAST_SETTING structure.
I cannot test either of them since I currently do not have any computer with Windows nearby. I hope, however, they point you in the right direction.
References:
The Old New Thing : Fumbling around in the dark and stumbling across the wrong solution
Recursive hook ... - borland.public.delphi.nativeapi.win32 | Google Groups
Registering for Power Events (Windows)

Categories

Resources