Controlling an RS232 Device over UART / WiFi

I recently had the need to connect part of my AV setup to my Home Assistant instance, however to do so I had two options, using the LAN control option built into the device, or via an RS232 serial port.

Naturally I attempted to use the LAN control part first, which involves opening a TCP socket to port 10008 of the device.
But I ran into problems as the connection kept wanting a user to login, even though there was no user account, and I was unable to figure out how to pass the login prompt and send commands automatically.

So I went to JayCar and grabbed one of these:

https://www.aliexpress.com/item/32722395554.html

Basically, it converts a TTL level signal to RS232 level signals.
I hooked it up to a Wemos D1 Mini, on the ESP, you want to use one of the HARDWARE UART pins, so for me, I went with D4, which is GPIO2 / TXD1.

My equipment had a 3.5mm socket for RS232 control, the manual had a pinout for DB9 to 3.5 so that was a simple cable to make, but your equipment might have something else.

Code wise, this is what ive settled on using and has been working MOSTLY well:

esphome:
  name: sharptv
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: '********'
  password: '********'

api:

# Enable logging
logger:

ota:

mqtt:
  broker: 172.16.0.60
  username: rs232
  password: ********

uart:
  baud_rate: 38400
  tx_pin: D4

switch:
  - platform: uart
    name: "Power On"
    data: [0x50, 0x4F, 0x57, 0x52, 0x20, 0x20, 0x20, 0x31, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/state
          payload: "ON"
          retain: true

  - platform: uart
    name: "Power Off"
    data: [0x50, 0x4F, 0x57, 0x52, 0x20, 0x20, 0x20, 0x30, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/state
          payload: "OFF"
          retain: true

  - platform: uart
    name: "HDMI 1"
    data: [0x49, 0x4E, 0x50, 0x53, 0x20, 0x20, 0x31, 0x30, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/input
          payload: "HDMI1"
          retain: true

  - platform: uart
    name: "HDMI 2"
    data: [0x49, 0x4E, 0x50, 0x53, 0x20, 0x20, 0x31, 0x33, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/input
          payload: "HDMI2"
          retain: true

  - platform: uart
    name: "HDMI 3"
    data: [0x49, 0x4E, 0x50, 0x53, 0x20, 0x20, 0x31, 0x38, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/input
          payload: "HDMI3"
          retain: true

  - platform: uart
    name: "DISPLAYPORT"
    data: [0x49, 0x4E, 0x50, 0x53, 0x20, 0x20, 0x31, 0x34, 0x0D, 0x0A]
    on_turn_on:
      then:
      - mqtt.publish:
          topic: esphome/rs232/sharp/input
          payload: "DISPLAYPORT" 
          retain: true

I say mostly, because when the ESP reboots, it sticks some data out of the pin, which the equipment holds in its buffer. So if the ESP has just reboot, and I try and send a command, the unit wont respond, as it gets more data than it thought. 🙂

This can be fixed by including a line break and carriage return at the START of the command, to clear the buffer, or by sending the command twice. but i havent done that yet because i … havent got around to it… 

Ill also mention, the TX/RX might be wrong on the Chinese board because ive seen a few different photos, if it doesnt work on TX try RX :^)

Ive ordered a handful of these to test making it smaller (think a cable with a bulge in the middle)

https://www.aliexpress.com/item/32834977750.html


Vivid 2018 LED IoT Apparel !

Hello! 

Continuing with the tradition of creating something beautiful and covered in LED lights, this year we have something special!

Previously, we had the LED Jacket with Tearschu, and the LED Dress with Naifel. Taking inspiration from these, and solving a lot of the problems I faced with them, I bring the latest iteration of light up fun.

This year, I have taken a pair of high heel boots, and an umbrella from Daiso, added plenty of pretty lights, and of course, this year marks the first year the entire project is connected to the internet.

 

 

The project was built using mostly the same core components for each item. 

The shoes each have:

  • Lithium Ion Battery (1000mAh)
  • LiIon Charge / Boost circuit MP2636 
  • WeMos D1 Mini
  • A random switch for power
  • A strip of WS2812 LEDs

The umbrella is similar, except instead of the MP2636 boost circuit and 3.7v Lithium battery, I used a 3s LiPo battery, and a 5v step down regulator capable of high current.

 

The physical build was pretty straight forward, hook up everything how you please, battery to boost/charge, from there to the WeMos / LEDs, and then route the wires how you please. For LED placement on the shoes, I went with up along the front as I feel this will look the best having the light cover the most area, and for the umbrella I ran the lights down the spokes of the umbrella.

Unfortunately with my design you cant really CLOSE the umbrella anymore but as this is just for Vivid I am not too fussed 🙂 

To attach the LEDs to the umbrella I initially tried to use hot glue, but it was actually melting through the umbrella, and the parts that didn’t, did not hold very well, so I ended up using clear packing tape, as it does not seem to get in the way of anything and is barely noticeable! 

The LEDs here are hooked up in parallel with each other, so each spoke on the umbrella will be the same.

Once it is all made up physically, we can move on to the code.

I was looking into using the McLighting project for control of these, as it has both an internal web interface as well as support for things like MQTT, but I could not get it to work reliably, and it didn’t support running in AP mode, only client mode, which was a big turn off for me.

So what I ended up using was the JSON LED code from BRUH Automation, because I use this for other things at home and it works pretty reliably.

One thing to note here, for my LEDs I had to add the following two lines of code, BEFORE including the libraries, to prevent flickering of the strip. (not sure why this works?)

#define FASTLED_INTERRUPT_RETRY_COUNT 0
#define FASTLED_ALLOW_INTERRUPTS 0

 

(at the verryy top of the sketch)

 

Now my initial plan included taking a small portable router, and a Raspberry Pi 3 out with me to vivid, running a local MQTT server on a local network, with the Pi running Home Assistant (Hass.IO) all locally so I could connect to it to control things. However I ran into many problems attempting to do this, I am not sure if its because I don’t know how to properly setup static IP’s in resin, or just because it hates me, but I kept not being able to connect or it wouldn’t respond to my commands, it just wasn’t working great.

 

One day though, my good friend Mark came over and we needed a project to work on, so what we set up was a private mosquitto MQTT broker, that requires authentication, running in Docker on a Ubuntu Server 18.04 LTS install!

What this meant,  was I now had a secure way of connecting a remote node to my Home Assistant running back home.

 

I went right ahead and adjusted the code on the three items for the new server, forwarded the ports in my router, added the config to my production Home Assistant server, and hey presto, was I glad to see, everything JUST WORKED.

 

I made a view in Home Assistant and threw all the entities into it, and here’s how that looks:

So as you can see, we can control both shoes together, each individually, the umbrella on its own, or everything as a group!

We also can change the animation speed of the various effects.

I will be heading out to vivid to shoot a small video and some photos with this, with my good friend Tsugumi modelling it for me, on the 9th of June 2018 from about 6PM onward, Not sure if I will be at Circular Quay or Darling Harbor yet, keep your eye on my Instagram to find out! 😉 

 

Thanks for reading!!!

Programming my Gherkin

Over the weekend at the Sydney Mechanical Keyboard Meetup, I got my hands on some DSA keycaps, The intent is for them to replace my dodgy sticker based ones on the Neutrino, but for now I decided to put them on the Gherkin to see how I fair with it having DSA keycaps on it! 

 

I forgot the keymap I had programmed so it is easier to just remake a new keymap imho.

 

Ill document it all here for future reference to stop myself forgetting next time 🙂

 

 

So as usual, we will use http://kbfirmware.com  

 

Now if you havent seen the gherkin its a 30%? 40%? keyboard, that has a 10*3 matrix on it.

 

More info here: http://www.40percent.club/2016/11/gherkin.html

 

Now we’re pretty lucky, on this page we have links to a json file for the firmware builder ! Lets use this!

 

 

The wiring is pretty funky if you ask me, its  very confusing. So i’ll just assume that it’s correct..

 

 

Now mine has LEDs so for those, Ill connect pin D3 on the header to the DIN on the WS2812 strip.

 

Using the handy pictures over here we can see the pinout of that header.

I have 11 LEDs so we will set that in the firmware builder and set it to D3 pin, Don’t forget to disable the other LEDs we aren’t using such as caps lock and num lock.

So ive messed with the layout and happy with this I think for now:

 

Now that I have configured everything, I have a custom json file

 

Lets download the hex file and flash it !

 

and we have success !

 

Everything works as intended 🙂

Thanks for reading !

 

edit: I changed some keys and added an esc key on layer 1 of N key thats all

Arcade Upgrade

So I had in front of me an old arcade machine, not too old, pretty new actually, a date code inside puts it around 22 June 2012.

Nevertheless, it was old in terms of mechanics.

The machine used a Jamma board, and was non functional.

I opened it up and had a bit of a look for any obvious electrical problems, burns out components, loose connectors, dirty connections etc. Couldn’t find anything.

For benefit of the doubt I used isopropyl alcohol to clean the PCB and the Jamma connector. Still no luck after this though.

The machine itself would power up, the board had power, but it wouldn’t output any video…

So I decided to go with my plan B, upgrading the machine to a PC based MAME emulator!

I started with physically cleaning up the machine, isopropyl and some Glen 20 did the trick, once it was nice and clean I got to the insides.

Snapped some photos of how everything was connected for future reference, and started removing components.

I can’t remember the whole process super well as it was a few days ago but I’ll recap best I can.

With all the main control and power boards removed, I was left with some bundles of wire cable tied inside.

I decided the best path would be to cut the bundles of wire that lead from the buttons to the Jamma board a short distance from the connector. This way in the future, reconnecting the Jamma connector is as simple as matching up the coloured wires.

I located the power connector for the button illumination, and tested it out. It was originally on the 12v from the power supply, I tested it on 5v and the buttons lit, but not the joystick. So I’ll just reconnect this to 12v once rebuilt.

I tested the screen using an HDMI to VGA adaptor coming from a PC that was nearby and got video out, this was great, was going to be pretty simple from here on out.

The screen is mounted in portrait which is going to prove annoying as most games these days and games I’ll be emulating will feel smaller. Also, it means that I’ll have to figure out how to display artwork above and below the emulation. Maybe themed to the console ?

I know there’s plenty of options online for ‘arcade button controller’ ranging from $6 to $100+, and I’m sure any of these would have done the trick, but I didn’t really want to wait for something to arrive, I wanted to finish this project in one day.

Luckily I had an Arduino pro micro laying around, I slapped some headers on it and some matching headers on the wires, then ran to the internet in search of a joystick emulation library for AtMega32u4 🕹️

It was actually very easy and within 3 results I had a library downloaded and installed!

Loading up the Arduino IDE I opened an example sketch that had 1 button and a joystick, this was SUPER easy to modify for the 5 buttons on the front panel of my machine, it was just a case of increasing some numbers and adding some extra cases!

I uploaded the sketch to the board and hooked up the buttons to their corresponding pins on the board, now it was time to test.

Hooked up the Arduino to my laptop and checked devices and printers, to my great surprise I saw a gamepad icon with Arduino Leonardo under it, that will be my board!

I right clicked it and hit Gamepad Properties, which brings up a screen where you can test everything.

The joystick was rotated left 90 degrees, so I suspect it was installed sideways as I used the labelling on the PCB for which wire was which, but after switching those wires around everything worked ! All the buttons and the joystick worked flawlessly now !

So now that I had the controls upgrades to modern universalness, I moved onto the speakers, there is two 10w speakers mounted to the rear of the cabinet, these used to be driven by the Jamma board, but with that gone I needed something new.

Coincidentally, a few days earlier, my friend James was over to fix my 3D printer, and had brought over a wireless speaker thing, that I didn’t know what to do with. But this thing, had a speaker driver in it, and also a 3.5mm input, so I put the transmitter unit aside and used just the receiver unit. Hooked up both audio channels with a wire so we got both left and right channel out of the speakers, and hooked them up to the device. I cut off its power cable so I could hook it up to an alternate source of power later, just 12v.

I decided it would be best to re use the original power supply, but some changes were in order. For starters, the damn thing had no earth, so adding an earth connection was my first priority, very simple and I don’t know why the original builder didn’t ???

Once that was hooked up, I proceeded to hook up the leds and the speaker driver to the 12v rail, and then pigtailed the monitor off the AC terminals, and also a cord with a 3 pin connector suitable for a laptop PSU on it.

With all the power sorted I turned to how I’ll drive everything.

I had a few options at my disposal, but given the tight space restrictions in this bartop size machine, I went with an Intel Nuc that I got last time I was planning to build an arcade machine.

I placed it inside, with some very strong Velcro, and placed its power adaptor next to the one for the monitor, also held down by Velcro.

I hooked up a USB wifi adapter and the Arduino to the back USB ports, as well as a mini HDMI to HDMI, then HDMI to VGA adaptors, to the mini HDMI port on the back. And it was time to power it up and test.

The Nuc booted and everything was fine.

I refreshed windows to a clean install as there was still many remains of my last attempt at getting things up and running, rotated the display 90 degrees to make it normal, and then fired up Project 64 for some testing !

I quickly learnt the volume was waayyyy too high, but was easy to fix. Just startled me! Haha

The controls worked great, and the picture looks fine. The colours are a bit off but I can fix that later.

For now this is enough, I’ll work out the software later as that takes aggesss to get setup nicely and all pretty like.

In the past I’ve used HyperSpin but I might give something new like GameEx a try.

I’ll make a new post once I have done that!

Album below (Please excuse the potato photos):

 

RGB LED Jacket ft. Tearschu

Last year, Tearschu and I worked together to bring the LED Dress to life, and that was a huge success!

 

This year, I worked with Tearschu to create another RGB item of clothing!

 

Tearschu designed and made a jacket with a clear PVC material, and we incorporated a strip of 144 WS2812b RGB LEDs into it, this was a challenge, as the power draw was too much for the 3-5A 5v power regulator we used last year.

 

We needed a much beefier 50W power supply! However thanks to some help from Reddit user /u/krhacken we were finally able to get brightness control working mere days before the shoot!

 

This allowed us to dim the lights for scenes where they were too bright, and for when we were just walking around between locations to conserve power!

 

We were able to go the entire 3-4 hour shoot with a single Turnigy NanoTech 1.6Ah 3S LiPo!

 

Im really happy with how the photos turned out and I can’t wait to make something for next year!

 

Make sure you ‘like’ the photos on Facebook!

 

 

And check out the album below!

 

ESP8266 Arduino Pro Micro 

I was looking everybody’s favorite online store for Atmega32u4 based MCUs for a friend and stumbled upon this little guy:

http://ebay.com.au/itm/191890522764

It sure as heck isn’t a 32u4 but it is rather interesting !

It looks like it’s an esp8266 module in the form factor of an arduino pro micro, I’m a bit put off by the $20~ price tag but it would be interesting to see if they have routed the pins to the corresponding ones as for the pro micro. 

Then you could use it as a drop in replacement without even having to change the code, except you would suddenly have the option to add wifi to your project! 
IoT is definitely getting much easier these days to implement than when this blog first started! Hahaha
No more fumbling around with an Arduino Uno with Ethernet and then little dodgy radios talking to other Unos with the same radio…..

Oh man that was hell 

LED Dress was a success!

Hey all!

Just a quick update to let you know the LED Dress was an awesome success!
It looked better than I imagined!

Once again I want to express a huge thanks to Tearschu for making the dress perfectly, and Naifel for modelling it so beautifully! (Thanks Tim for helping too!)
It’s an amazing feeling having an idea and making it become a reality!

Heres some sneak peeks before I get around to editing the photos:

 

 

 

 

Original post can be found here: http://blog.lewys.eu/?p=254

LED Skirt mark 1

I decided that this year for Vivid Sydney, I will do something I have wanted to do for a long time.

I am going to create an LED skirt.

I got the inspiration from SexyCyborg with her LED skirts over here:

My DIY Underlit LED (Hikaru) Skirt

I’m going a slightly different approach though.

Rather than just skirt-underlighting I am commissioning Tearschu to make a frilly skirt similar to this dress here

Edit: found some similar to the look im going for!
http://www.instructables.com/id/LED-Skirt/

Dress I made for my Senior Prom, hope you guys like it!

I am going to be embedding some strips of WS2812B addressable LEDs into the skirt, hopefully it’s going to give a nice washed colour effect into the whole skirt!

I will post progress pictures as I go with the build.

Parts list:

LEDs: http://www.ebay.com.au/itm/162068083230
Arduino Nano: http://www.ebay.com.au/itm/182093493024
Power UBEC: http://www.ebay.com.au/itm/271700451532
B
attery: Turnigy NanoTech 3s LiPo

 

Power source:

I am going to use a hobby UBEC that can do 5v at 3-5 amps 🙂
I have linked it above under the parts list. It will be connected to a 3s LiPo battery for powering both the arduino and the LED strip.

The LED strip can draw up to 3.5 amps at 5v at full brightness, this will only really happen if all the LEDs are lit, and white. but to be safe I am investigating power sources that can handle this.

I may end up just using a USB battery bank with its 2.1 amp output.
I am pretty sure thats all ill need.

Nevertheless I have a reddit post in /r/askelectronics over here where I am asking if there’s a better solution!

Some other projects that I may find useful to refer to:
https://hackaday.io/project/603-bluetooth-controlled-neopixel-lamp
http://www.instructables.com/id/Control-RGB-lights-from-Android-with-Arduino-Bluet/?ALLSTEPS

Prototyping!

I rigged up a little 3 pixel test strip to get the code worked out, ideally I want to have a push switch that can change between colour patterns / modes.

View post on imgur.com


I’m looking around to see if this has been done before because I’m terrible at code \o/


I did some testing with a 16 pixel ring to get a better idea of the colour mixing.
I really love the colours that come out of these things, they’re so vivid and will mixed!
I’m getting super excited for this to happen!

Update:

The electronics are ready!
I have completed it all and the power supply works and i’ve charged up the batteries!
Check out these pictures:

View post on imgur.com

Update: 
The code is ready!
I have uploaded it to GitHub here: https://github.com/CountParadox/NeoDress/
It’s made from a number of places and things mashed together, it has a few modes, and is fully configurable of course.
Tactile switch on digital pin 2, leds on pin 6, set for 60 leds at the moment.
has an off state, a rainbow chase, and a number of solid colours because they’re nice!

And here’s a video of the strip!


More to come…

HamShield Motion Sensor

I am in need of a motion sensor for something, and I have this HamShield that I got from KickStarter recently.

 

heres some code I have mashed together that *MIGHT* make the radio send an SSTV image when motion is triggered..

 

I have to rest it and refine it first! its just mashed code from examples!

[su_expand more_text=”Code:” less_text=”Close Code.”]/* Morse Code Beacon Test beacon will transmit and wait 30 seconds. Beacon will check to see if the channel is clear before it will transmit. */ // Include the HamSheild #include #define PWM_PIN 3 #define RESET_PIN A3 #define SWITCH_PIN 2 // Create a new instance of our HamSheild class, called ‘radio’ HamShield radio; int calibrationTime = 30; boolean sensorActive = false; boolean previousSensorState = false; int pirPin = 4; //the digital pin connected to the PIR sensor’s output // Run our start up things here void setup() { // NOTE: if not using PWM out, it should be held low to avoid tx noise pinMode(PWM_PIN, OUTPUT); digitalWrite(PWM_PIN, LOW); pinMode(pirPin, INPUT); digitalWrite(pirPin, LOW); // prep the switch pinMode(SWITCH_PIN, INPUT_PULLUP); // set up the reset control pin pinMode(RESET_PIN, OUTPUT); digitalWrite(RESET_PIN, HIGH); // Set up the serial port at 9600 Baud Serial.begin(9600); // Send a quick serial string Serial.println(“HamShield FM Beacon Example Sketch”); // Query the HamShield for status information Serial.print(“Radio status: “); int result = radio.testConnection(); Serial.println(result,DEC); // Tell the HamShield to start up radio.initialize(); radio.setRfPower(0); // Configure the HamShield to transmit and recieve on 446.000MHz radio.frequency(145570); Serial.println(“Radio Configured.”); Serial.println(“Sensor Calibration in Progress”); Serial.println(“——————————“); for(int i = 0; i < calibrationTime; i++){ Serial.print(“.”); } Serial.println(“”); Serial.println(“Sensor Calibration Completed”); Serial.println(“Sensor Reading Active”); delay(50); sensorActive = false; previousSensorState = false; } void loop() { // takes the pin value and saves it to the sensorActive boolean value if(digitalRead(pirPin) == HIGH) { sensorActive = true; radio.setModeTransmit(); // Turn on the transmitter delay(250); // Wait a moment radio.SSTVTestPattern(MARTIN1); // send a MARTIN1 test pattern delay(250); radio.setModeReceive(); // Turn off the transmitter } if(digitalRead(pirPin) == LOW) { sensorActive = false; delay(250); } // performs action if the state of the sensor changes // since this is a loop, here is now it works: // if the sensor pin goes HIGH (on) after it being LOW (off), the sensorActive value changes from the previousSensorState value. // it then turns on the LED. when the pin goes LOW (off) it will do the same thing but opposite values. // it also prints status to serial. it will print the time of triggering by providing the number of seconds that have passed since the program started. if(sensorActive != previousSensorState) { if(sensorActive == true) { previousSensorState = sensorActive; Serial.println(“—“); Serial.print(“Motion Detected At: “); Serial.print(millis()/1000); Serial.println(” Seconds”); delay(50); } if(sensorActive == false) { previousSensorState = sensorActive; Serial.println(“—“); Serial.print(“Motion Stopped At: “); Serial.print(millis()/1000); Serial.println(” Seconds”); delay(50); } } } [/su_expand]

OLKB Neutrino Keyboard

This week I’m finally making great progress with my hand-wired mechanical keyboard.
I had finalised the electronic hardware a while ago, and now that a colleague has helped me out with programming the Teensy 2.0 the only thing that remains is to get some nice keycaps for it to replace these cheap red placeholder caps, and to create a nice case for it.
I am thinking ill go with something wood, but I am not sure how ill mount it in yet.

I also made a custom USB cable by buying some paracord, slicing the ends off an Astro Gaming USB Cable, spending hours sleeving the cable into the paracord, and then resoldering some connectors to the ends.

The heat shrinks pretty damn messy, ill tidy it up some time but it works for now.

Anyway please enjoy these short albums of photos:

View post on imgur.com

View post on imgur.com