Overkill spark light switch

Hey everyone. So i think its times i start working on my sparkcore some more. Right now i have one that sits on a shelf controlling a 5m led strip.

My partner suffers from epilepsy so having dimming lights was something i really needed, i had an arduino before but spark was sooo much easier.

So right now i have my spark sending out basic pwm signals, these get lifted up to 5v in order to control a 12v fet. (I need to build a new power board i think)

With that said right now i have an android control app on my phone to adjust brightness settings, turn the leds on and off, and give me a light sensor reading. Basic stuff i know. But my partner is too lazy to use it, and often turns off the usual light switch instead of messing about getting out a phone.

So i thought, why not take advantage of the new spark subscribe feature, or even some I2C communication and mount a small touchscreen to my wall to act as a light switch. Overkill i know.

The core controlling my lights is around a meter away from where i want the light switch to go. So i had a few questions to ask as i am very new to spark still (the only library ive used is the real time clock)

What i plan to do is use a second spark core to check for motion, or the touchscreen being pressed to trigger my lights. I understand the methods needed for the cores to talk but i need some advice.

I have never used I2C but it looks very useful. But i believe it has signal length limits? So would you

A) use the current spark and connect an I2C touchscreen to it and get that to check if its been touched? Maybe getting x and y positions?

B) Use a second core to do the same and have them communicate wireless, atleast that way i could move the switch around and the controllers to different rooms

Now with that i did look over the other post about screens to use with the core, but i would like to create an interface for the button so it looks nice, would i be able to do this with a colour I2C touchscreen?

Programming wise i have very simple knowledge so i will have to read into it more but so we think my proposed project is possible? So to outline what i want to do

Have a colour touchscreen, with an image drawn to mimic a button, maybe a slider to adjust brightness? Get the x and y positions and the core can do position checks for me. Its just finding a good I2C display that i can read x and y positions along side creating an image

Sorry if it didnt make much sense, i will try to re-explain if requested.

Regards,
Jamie

ref 1 - Example of the display, crude but simple

3 Likes

Bigjme, 4 systems make great touch screen displays, albeit somewhat more expensive but use serial communications and have a fantastic screen designer. I ported their library some time ago. Another source could be www.buydisplay.com as they have some touchscreen units as well.

I have been looking at buydisplay. They seem to have some pretty good screens. At $40 their not very expensive but import to the uk will be a killer. Not too bad though

I believe they have sd cards slots on the back so i could store a template image, then i would have to draw on the slide bar, and add the text. But that shouldnt be too bad following their i2c sample code. The code for it which is written directly in C looks very long however and im wondering if the spark would be able to store the length of code they use.

Ideally i dont need a 5" screen as it will be huge but, i can always re-use it later on for a media controller or something. Especially when $40 is only around ÂŁ24

Have you considered using capacitive touch for buttons? You could create a toggle button, as well as an intensity slider, or different modes. Ideally you could even hide the buttons behind/underneath something, so it’s aesthetically more appealing. I pointed out a breakout board here which I’m personally very happy with.
It’s a lot easier to implement, requires minimal extra hardware/software, uses your original core, and is generally ‘magical’ to use.
Thought you might be interested. Either way, good luck ;)!

Ive never really looked into those. They seem like a pretty cheap way to do it. I cant really find anywhere selling them in the uk, or an alternative

I think they’re pretty nice. They can detect presence from a few centimetres away, which is great if you want to conceal the electrodes. They’re rather cheap as well, and you can use them on other projects if this one isn’t the right fit after all.
Like I said on the other thread, I got them from Aliexpress, but Sparkfun has them, as well as some China/Hongkong sellers on Ebay.

ok, so i would need one of these

i then need to get some of these?

would i be right in that?

I only have the breakout board, the top one. It has twelve individual sensors, to which you can connect your ‘buttons’ with wires. Unless you would like to create some more remote individual buttons, you shouldn’t need the small boards (lower ones). With those you’d have to touch the actual board, which isn’t necessary with the top one.

So with the top board your setup would look somewhat like; Spark -> breakout -> wire (-> button). The button can be any conductive material. Aluminum foil works nicely.
The lower board would be more like Spark -> breakout, with which you’d have to touch the breakout.

If you like I can take a picture of my test setup when I get home, might make it easier to visualize.

That would be great! I could maybe put up 3 sensors;

on/off
Brightness up
Brightness off

Due to upload limits in the forum I posted them on my NAS: pic 1, pic 2, pic 3, pic 4.
I’ve only attached 4 wires for testing purposes which have worked great so far. Since you’ve got 12 of them you could create some fixed brightness levels, an up/down, on/off, maybe even some different fade modes. The possibilities are limited by your skills/creativity only.
Just to clarify; I’m not trying to talk the touchscreen out of your head, just presenting you with an alternative I’m currently playing around with. I can in no way guarantee it’s going to be better, but I thought I’d let you know anyway :wink:

1 Like

I may have to get both :wink:
Can i ask why your using D0, D1, and D5?
I know you used 3.3v, ground, and the link between ADD and ground to set the address

I know you need scl and sda for the 2 wire, but whats the 3rd wire for? And i take it D0 and D1 are scl and sda?

Looks like D5 runs to the /INT (interrupt) pin on the breakout board. When the sensor detects an input change, it /INT goes low. You can watch for that change, then do the I2C communications to get the readings.

https://learn.sparkfun.com/tutorials/mpr121-hookup-guide/communicating-with-the-breakout-board

1 Like

Ahh so when a change is detected on a sensor it triggers the interupt pin to go low, the pin changes state and the spark just checks the current state against the last state.

Would prevent the code from having to read the i2c line which i expect would cause some issues

That sounds about right :slight_smile: I ended up using this tutorial/code; http://bildr.org/2011/05/mpr121_arduino/ It’s linked to from Sparkfun, and works nicely for me. You could give it a try.

Ahh, so now i need to find some electrical surface that’s going to look Ok stuck to my wall :wink:
have you tested how well the electrodes pick up with long lengths of cable? ideally i only want 1 cable coming off the controller to start and the cable would be pretty long (~1m), and also does cable size matter?

for example if i wanted 4 sensors and used a small 4 core cable, one core per electrode, would it effect things?
lots of questions i know, but i have a long wait before my controller arrives :frowning:

You could print out a nice picture, and paste it over some aluminum foil. That’s the neat thing about these sensors; you can hide them behind stuff, so you won’t actually see them. I’m personally planning on stuffing aluminum foil behind my wallpaper so they’re completely hidden. But then again, my walls are yet to be done, so I don’t have to destroy stuff to do so. You’d be better of with placing something over it, especially for testing.

I have not yet tried any other cables. The cables I used where from a UTP cable I stripped. The cables actually respond when you touch the isolation, so that might become a problem. If I get home I could test this with some longer UTP (~1m’ish) if you like, while still wrapped together.
Alternately you could use a longer wire from the board to the Spark. These wires shouldn’t interfere with each other. I’m not sure if that’ll work for I2C though, having read that it’s meant to be for short, ‘interPCB’ communication. The board itself is really small, you could could hide that somewhere behind a nice painting, or something like that, if this does work.
Hovering over certain part of such a painting is also a nice lighting control :wink:

Lmao. The rooms a funny shape so i would have to stick the metal to the wall, or over my current light switch.

It would be great if you could test it. I dont mind even if you have to touch it to set it off, i know you can drop the sensitivity. No idea how but yeh :stuck_out_tongue:

so my sensor finally came, would you be able to post your code for me @Moors​7
i am not entirely sure what i am doing :frowning:

Edit:
ok so i got it working, it is just very sensitive, looks like i need to figure out how the sensitivity settings work

Edit 2:
so i have adjusted the sensitivity, up to the point where it takes my entire hand to set it off. but for some reason it sets itself off for no reason.

it has a 255ms gap between pressing and it saying your pressing it to prevent bouncing but it keeps setting itself off sometimes for no reason. right now i am using the code that was posted by Moors7, any ideas?

i have the cable for the sensor around 35cm long, wrapped in tin foil on a stripped 5cm section. taped perfectly flat, sensitivity has been upped even more now to 0x2A. I have made sure no other cables are near, and it can be fine for ages then just start detecting signals from nowhere.

it is connected to the 3.3* connector for smoother voltage, its just weird

1 Like

Hi Bigjme or Moors7,

Any chance you could post your exact code for running the mpr121 breakout board on the spark core? I have been reading the bildr tutorial on using the MPR121 with an Arduino, but I’m not succeeding in making it work on the spark core. To start with I’m missing a “Wire.h”-file the code is referring to and I guess there are a few other “translations” that need to be done to make the arduino code run on the spark core?

This is all pretty new to me, so I’m trying not to drown in all the information available out there. :wink:

thanks!

I can use the library from Sparkfun with any MPR121 breakout board? Like the generic one from china or the Adafruit version of it? and not stick to the Sparkfun version?

Thank you for your help…