Showing posts with label Serial. Show all posts
Showing posts with label Serial. Show all posts

Thursday, 10 December 2020

Live-edge oak spotlight light fixture - part 2 - adding ambience

In my previous post, I built a hanging light fitting of live-edge oak and recessed GU10 spotlights.

There is actually more to the project.

Sometimes, spotlights can be a bit overpowering, and it's preferable to have some ambient, indirect light.

During construction, I had the idea of creating this light in a way that would allow use of the spotlights, an ambient light, or both.

To create the ambient light, I used LED strips on the reverse (upward-facing) side, to reflect light off the ceiling.

I cut some thin strips of oak with a 45-degree angle and mounted them in a rectangle on the back - angled side outward, to help direct the light. An RGB LED strip was mounted all around this.

Control

I initially thought of using the LED driver that tends to come standard with rolls of LED strip, but as the existing wiring leads to only one switch, without some rewiring through the ceilings/walls, it would be limited to either having both the spotlights and the ambient light on, or just the spotlights on without the ambient light - it would not be possible to have the ambient light on without the spotlights.

In order to combat this, and to lay groundwork for a potential future project, I included a solid-state relay and an Arduino. The arduino would drive TIP31 transistors to drive the 3 channels for the LEDs red, green and blue, and additionally control a solid state relay which would act as the switch for the spotlights.

The idea would then be that the light switch would remain on, more like a utility switch, and then all control of the light fitting would be handed over to the Arduino.

 

Power

 

The original wiring sketch.
it's just a rough sketch,
not a proper wiring diagram.
 
The LED strips take 12V, and the microcontroller takes 5V, so a PSU is needed to bring the power down to usable levels.

For this I used an old net-book power supply. This was wired into the back of the light fitting. Caution is needed to make sure that nothing too powerful is used, as typically a houses' lighting circuit breaker is tripped at a much lower current than the mains sockets.

 

Revised to include the additional components
This would normally be plugged into a wall socket, where it's plug would have a fuse. However in order to wire this into the lighting wiring, the plug would need to be removed - obviously this introduces a safety concern. To ensure that this would still be fused, I replaced the wall switch for the light to one that includes a fuse, ensuring that the light is behind the fuse.

 

Communication

To communicate with the Arduino, I used a cheap HC-05 bluetooth to serial adapter, the same as I've used in other projects like the Bluetooth Macro keyboard app.

The arduino receives 4 bytes, followed by newline characters. These correspond to 1 byte each for the red, green and blue channels in the LED strip, and the final byte is either a simple 0 or 1 to indicate if the spotlights should be on.

For now this is sent by pairing with my phone and using a bluetooth serial terminal app from the Google play store. I'll probably create a more custom app in future, but for proving the concept, this works just fine.

 

Monday, 22 June 2020

Context-sensitive macro keypad

I've been doing quite a bit of 3D work recently for both 3D printing and VR software development.

The main software that I use for 3D work are OpenSCAD and Blender.

One annoyance I have is that the short cut keys each use for standard things such as scale, rotate, move, etc. are all different, which makes switching between applications more awkward than it need be.

So my latest electronics project is to create universal short cut keys - a physical keypad that has single button presses for those functions, but then translates them into the relevant keyboard/mouse presses dependent on which application has focus at the time.

The hardware
As we're still under lockdown due to COVID-19, I'm restricted to using only components and tools I have got at home, like with the USB Switch project.

The keypad itself is this mechanical key switch tester.



Unfortunately the eighth switch was lost some time ago. I'll leave the gap there as potential room for expansion in future though.

The controller is an Arduino Pro Micro. I thought about using a different microcontroller, however the real sticking point was my lack of a spare USB to serial adapter.

The Pro Micro helps keep the overall form factor nice and compact, whilst keeping the programming side of things straightforward.

I picked out some LEDs to backlight the keys as there was spacing for them, and the keycaps are translucent. I tried to find all different colours, but my inventory didn't allow for that, so there's a couple of duplications.

The rest of the hardware is just some diodes and resistors, a bit of perfboard and some scavenged wires.

The hardware is wired up like so:
Quite simply, there's two matrices, one for the switches, and one for the LEDs. Because of the missing key, one column in each only has three connections.


The case is just some plastic container that would otherwise have been trash. It wasn't a perfect fit so required some Dremel-based customisation.

The Firmware

The Arduino will stay set up as a USB to Serial device rather than as a keyboard because there needs to be bi-directional communication - the Arduino needs to also receive input from the application in order to control the lights.

This post was a useful resource when putting together the matrices.

The full source is available in the project on GitHub.

The Software
The software is a java desktop app that communicates with the Arduino using jSerialComm. It controls which keys are 'set' and indicates this with the LEDs.

The interfacing with the other applications comes from a thread that uses system calls to the 'xdotool' linux command, reading in the output of that command which is the name of the current window that has focus. There's room here to make the application multi-platform, by implementing a similar Windows command in something like AutoHotKey.

If the window matches the defined rule set, the relevant keys are highlighted and a thread monitors serial input. If that key is pressed, java built-in Robot class sends the relevant commands to the application.

As with the firmware, the source is available on GitHub. It's in a pretty simplistic state at the moment due to the one-week time limit I've placed on these lockdown projects, but there's room to expand and improve in future.

Thursday, 4 August 2016

App Update - Bluetooth Macro Input v.1.5


What's New
  • Command support - now send keystrokes for non-character keys - function keys, CTRL, ALT, etc.
  • Bug fix - Bluetooth no longer connects on application load - this prevents some crashing on open. Connection happens when the first bit of text is sent.
Usage
On first run, use the menu button, select settings from the menu and set the options you wish to use.

The most important settings to choose here are "Use Bluetooth Connection" and the bluetooth MAC address for your device. If you do not set a directory for storing your macro files, the default directory is a folder called "BluetoothMacroFiles" under your devices storage location (e.g. /storage/emulated/0/BluetoothMacroFiles).

Once that's done, you can swipe between the two main screens. The first is the voice recognition screen. Tap the button, speak, wait for Google voice recognition to process your speech and a series of possible options are presented.
Tap your chosen option and the device will attempt to send that text through to the bluetooth adapter.

The second screen allows you to select a text file from the menu and send that via bluetooth. The new functionality allows you to define keystrokes for non-character keys - handy for sending commands. For example, a text file containing the following:

{F11}Hello World

will 'press' the F11 key, and then type "Hello World". The extra keys you can type in this manner are:
  • CTRL
  • SHIFT
  • ALT
  • RIGHT_CTRL
  • RIGHT_SHIFT
  • RIGHT_ALT
  • RIGHT_GUI
  • BACKSPACE
  • TAB
  • RETURN
  • ESC
  • INSERT
  • DELETE
  • PAGE_UP
  • PAGE_DOWN
  • HOME
  • END
  • CAPS_LOCK
  • RIGHT
  • LEFT
  • UP
  • DOWN
  • F1
  • F2
  • F3
  • F4
  • F5
  • F6
  • F7
  • F8
  • F9
  • F10
  • F11
  • F12
The arduino sketch adapter I use with the app is detailed here, and the hardware is a Pro Micro with a simple Bluetooth-to-Serial adapter.
In order to get the command functionality working I had to amend the arduino sketch - revised version below:


void setup() {
  Serial1.begin(115200);
  Keyboard.begin();
}

void loop() {
  if (Serial1.available() > 0) {
    byte inChar = Serial1.read();
    Keyboard.write(inChar);
    Serial1.write(inChar);
    delay(10);
  }
}



Support
As with all my apps, it is free, and as such, I am not in a position to offer any kind of official support, so use entirely at your own risk.
If you have any trouble with it, then feel free leave a comment or tweet and I'll try to help as and when I can, but I make no guarantees.

Get it on Google Play

Previous Versions
The original app
First update

Thursday, 6 March 2014

Quick Update

This is some code for an Arduino Leonardo that will receive character data from the serial pins, then echo the character through USB as keyboard input to the PC.
This will form the basis of a bigger project that'll be the subject of another post, but for now, here's the code:


void setup() {
  Serial1.begin(115200);
  Keyboard.begin();
}

void loop() {
  if (Serial1.available() > 0) {
    byte inChar = Serial1.read();
    Keyboard.write(inChar);
    Serial1.write(inChar);
    delay(10);
  }
}