Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control with arduino #6

Open
Phil1988 opened this issue Nov 24, 2015 · 8 comments
Open

Control with arduino #6

Phil1988 opened this issue Nov 24, 2015 · 8 comments

Comments

@Phil1988
Copy link

Could someone please tell me how I could control the bulbs with an Arduino and a nRF24L01 module?
I can only see this on every start of the arduino:
"# OpenMiLight Receiver/Transmitter starting"

How could I for example pair the "arduino remote" with the bulb as group2 ?
I think I have to send some thing like this:
B0 F2 EA 7D B0 15 F0

But how do I enter it correctly in the SerialMonitor to send it?
Any help is highly appreciated!

I cant also receive anything as I am using the bulb with my original remote.
I can switch to
"# Escaped to extended commands: r - Toggle receiver; Press enter to return to normal mode."
"# Now receiving"

But after this nothing happens if I press buttons on my remote.
Hope you have any ideas.

Thanks a lot!

@VincentGijsen
Copy link

well, start of by checking that you have indeed the proper wiring setup.

After which, don't fiddle around on the Serial Monitor.
Instead: execute the python script on you computer, and point it tho the serial port where the arduino is available.
When you have that running, grab an app for your smartphone/pc/whatever and configure it to either broadcast or directly send it's UDP traffic to your pythons app (per default it listens on 8899).

if this works, than reverse engineer the Python script, as it mangles the UDP packages, prior to sending it to the aruino/msp430. The script will explain how to write the bytes into the serial buffer. You might like to improve the arduino side of things, to directly parse the packages (in which case, please share your modifications with the community!

@Phil1988
Copy link
Author

@VincentGijsen: Thanks you a lot for answering!

I am sure that my wireing is right (I also wrote a simple "chat program" between my two nRF24L01 modules to check if they can communicate and they do).

Sadly I'm not familiar with python (and I am using Win7).

I installed Python 3.5.1 on windows and run cmd after this.
When I now run the "openmilid.py" I get this error:


....\host\openmilid.py", line 109
print fd.read(1024)
^
SyntaxError: invalid syntax


So I dont know how to execute the python script neither how to point it to the serial port of my arduino (COM 2).

You see I am already lost at the basics.
Could you explain this more to me or do you have a video how to do this?

I thank you a lot!

@VincentGijsen
Copy link

Hi,

Googleing, the first hit on SyntaxError: invalid syntax yields the following:
http://stackoverflow.com/questions/7584489/python-print-statement-syntax-error-invalid-syntax

This means your are using python 3 instead of two. which is basally ok, although printis a function, and functions are called using the parentheses so ( stuff ).

Just modify the line print fd(1024) into print(fd.read(1024))

I guess, after fixing this (and possibly other print statements), you may get an new exception that serial is unavailable.

You first need to install pip, which may or may not be available with your current python install, if not, google for python install pip

after which you may execute in your cmd box:
pip install pyserial

please note, i'm no python programmer whatsoever, google is occasionally my best friend

@Phil1988
Copy link
Author

Also if you are not a python programmer - your knowledge is far beyond mine :-)
this solved the problem and put me into new ones...


Traceback (most recent call last):
...openmilid_modified.py", line 129, in
OpenMiLiDaemon( args ).start()
...openmilid_modified.py", line 78, in start
with serial.Serial(self.args.serial, self.args.baudrate, timeout=0.1) as fd:
...\Python35-32\lib\site-packages\serial\serialwin32.py", line 31, in init
SerialBase.init(self, _args, *_kwargs)
...\Python35-32\lib\site-packages\serial\serialutil.py", line 171, in init
self.open()
...\Python35-32\lib\site-packages\serial\serialwin32.py", line 62, in open
raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port '/dev/ttyUSB0': FileNotFoundError(2, 'Das System kann den angegebenen Pfad nicht finden.', None, 3)


The only thing I see here is wrong is the port direction as it is linux like as /dev/.. and should be something like this:


import serial
ser = 0
def init_serial():
portnumber = 2
global ser
ser = serial.Serial()
ser.baudrate = 9600
ser.port = portnumber


But as you see... I am completely lost with this...

@VincentGijsen
Copy link

Hi Phil,

when you look at the last lines of the Host app:

<<SNIP>>
 parser = argparse.ArgumentParser(description='OpenMiLi daemon -- Listen for commands on the network and control Mi-Light bulbs.')
    parser.add_argument('--serial', '-s', help="Device node for the serial line to connect through", default="/dev/ttyUSB0")
    parser.add_argument('--baudrate', '-b', help="Baud rate for the serial line", type=int, default=115200)

You will notice that this is a parser for the command line options. When you run the script with `--serial ``, it will try to connect to the port.

The default is /dev/ttyUSB0, which refers to the first USB serial adapter in linux, for Windows, however you'll need to substitute this for COM1 / COM3, or whatever. Just consult your Device manager in Windows to check on with port your Arduino or serial adapter is registered. Probably you could try to use the same port the Arduino IDE uses.

Also ensure that the `baudrate`` (which defaults to 115200) is the same, both for arduino, as for the python app.

Should this still not work, you may uninstall Python 3, and install Python 2.7.

Than install pip, and try the unmodified version of the python app (so revert any changes for the print statements)

@rremigius
Copy link

rremigius commented Oct 15, 2019

Hi, I know I'm replying to an age-old Issue, but it's still open and I was hoping to find an answer here as well.

I just started out, got 2 Arduino's to message each other with RF24L01+ modules to verify I got the wiring right, and now I'm trying to get some packets on the screen - without any luck so far. The sketch is running on Arduino, the openmilid.py script is running and shows

# OpenMiLight Receiver/Transmitter starting

And now I don't know what I'm supposed to do. Nothing I do with my lamps or controller shows any feedback on the screen. I installed some Milight apps, pointed them at my computer and started pressing and swiping some colors. The most I got there was:

# Error: outgoing packet complete. Press enter to send.
# Error: outgoing packet complete. Press enter to send.

Even if they did show something, I wouldn't know how to use that information to control my lights from a script. I would have thought I would be able to see messages my controller was sending so I could imitate them... Perhaps I misunderstood how this library is supposed to work, but I can't get it from the readmes or code. Are there perhaps any sort of "Hello World" instructions that get you to your very first command-line light switch?

@VincentGijsen
Copy link

VincentGijsen commented Oct 16, 2019 via email

@rremigius
Copy link

rremigius commented Oct 16, 2019

Part of the problem is I don't know how to pair the bulbs to the address. I would have thought I would be able to sniff the controller signals and mimick them directly, pretending to be that controller, but that was the other problem - I was unable to read any signals.

I had some progress though. Since I'm using a RGBW+CCT controller, I used the code from this pull request: #9. Now I can use Arduino's Serial Monitor to send xr to the device and it starts listening (I tried using openmilid.py for that but it doesn't send my commands to the Arduino).

The signals are quite random. Pressing Group 1 'on' several times results in this:

D2 D8 74 B1 02 D5 B9 .................................
D6 CC D0 E5 B6 89 A7 ................................
60 7B 8E 42 C6 31 AA ................................
DA D0 CC E9 BA 8D 9F .................................

I tried copy-pasting one of the signals back in the Serial Monitor so it would send it, but the bulb doesn't respond to that. I tried sending it 3 times in a row after the unpaired bulb powered on but it did not pair. Also if I use 2 Arduinos with the same code in listening mode, one does pick up anything I paste in the Serial Monitor of the other.

I also tried using this code: http://arduino-projects4u.com/milight-new-protocol/ in combination with the pull request from sgentle which is able to decode the packets into less random signals:

<-- 09 61 56 2B 33 19 F8 7B 1A 52 Decoded package = 97 20 75 42 01 01 B4 01 ...............................
<-- 09 E2 C8 C4 E1 B2 85 93 72 6B Decoded package = 94 20 75 42 01 01 B6 01 ...............................
<-- 09 AE F4 98 8D DE B1 E9 9E 4D Decoded package = 40 20 75 42 01 01 B8 01 ...............................
<-- 09 BC 17 B2 9E A2 0D 4C A2 5C Decoded package = 72 20 75 42 01 01 BA 01 ................................

But I don't know how to use this information either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants