-
-
https://www.youtube.com/watch?v=NBf4JKflnyA
var distance = 0; var running; var on = 1; var global = [0,0,0,0,0,0,0,0,0,0,0,150,1,0]; var sensor = require("HC-SR04").connect(A0,A1,function(dist) { distance = dist; }); SPI2.setup({baud:3200000, mosi:B15}); function runIt(){ sensor.trigger(); if (distance > 9.5){ noMail(); }else{ gotMail(); } } function switchit(){ if (on){ clearInterval(running); on = 0; } else { global[11] = Math.floor((Math.random() * 100) + 50); running = setInterval(runIt, global[11]); on = 1; } } function gotMail(){ if(global[1] > 255){ global[1] = 0; } if(global[2] > 255){ global[2] = 0; } if(global[4] > 50){ global[4] = 11; } switch(global[4]) { case 0: blackOut(); break; case 1: SPI2.send4bit([0,0,0, 0,0,0, 0,0,0, 0,0,0, 50,0,0, 255,255,255], 0b0001, 0b0011); break; case 2: SPI2.send4bit([0,0,0, 0,0,0, 0,0,0, 50,0,0, 100,0,0, 255,255,255], 0b0001, 0b0011); break; case 3: SPI2.send4bit([0,0,0, 0,0,0, 50,0,0, 100,0,0, 155,50,0, 255,255,255], 0b0001, 0b0011); break; case 4: SPI2.send4bit([0,0,0, 50,0,0, 100,0,0, 155,50,0, 255,150,0, 255,255,255], 0b0001, 0b0011); break; case 5: SPI2.send4bit([50,0,0, 100,0,0, 55,50,0, 255,150,0, 255,255,255, 255,255,255], 0b0001, 0b0011); break; case 6: SPI2.send4bit([100,0,0, 55,50,0, 255,255,255, 255,255,255, 255,255,255, 255,255,255], 0b0001, 0b0011); break; case 7: SPI2.send4bit([255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255], 0b0001, 0b0011); break; case 8: SPI2.send4bit([255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255], 0b0001, 0b0011); break; case 9: SPI2.send4bit([255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255], 0b0001, 0b0011); break; case 10: blackOut(); break; case 11: SPI2.send4bit([2,0,0, 2,0,0, 2,0,0, 2,0,0, 2,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 12: SPI2.send4bit([4,0,0, 4,0,0, 4,0,0, 4,0,0, 4,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 13: SPI2.send4bit([6,0,0, 6,0,0, 6,0,0, 6,0,0, 6,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 14: SPI2.send4bit([8,0,0, 8,0,0, 8,0,0, 8,0,0, 8,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 15: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 16: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 17: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 18: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 19: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 20: SPI2.send4bit([30,0,0, 20,0,0, 20,0,0, 20,0,0, 20,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 21: SPI2.send4bit([155,50,0, 30,0,0, 20,0,0, 20,0,0, 20,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 22: SPI2.send4bit([30,0,0, 155,50,0, 30,0,0, 20,0,0, 20,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 23: SPI2.send4bit([20,0,0, 30,0,0, 155,50,0, 30,0,0, 20,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 24: SPI2.send4bit([20,0,0, 20,0,0, 30,0,0, 155,50,0, 30,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 25: SPI2.send4bit([20,0,0, 20,0,0, 20,0,0, 30,0,0, 155,50,0, 0,255,0], 0b0001, 0b0011); // white break; case 26: SPI2.send4bit([20,0,0, 20,0,0, 20,0,0, 20,0,0, 30,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 27: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 28: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 29: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 30: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 31: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 32: SPI2.send4bit([30,0,0, 20,0,0, 20,0,0, 20,0,0, 20,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 33: SPI2.send4bit([155,50,0, 30,0,0, 20,0,0, 20,0,0, 20,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 34: SPI2.send4bit([30,0,0, 155,50,0, 30,0,0, 20,0,0, 20,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 35: SPI2.send4bit([20,0,0, 30,0,0, 155,50,0, 30,0,0, 20,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 36: SPI2.send4bit([20,0,0, 20,0,0, 30,0,0, 155,50,0, 30,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 37: SPI2.send4bit([20,0,0, 20,0,0, 20,0,0, 30,0,0, 155,50,0, 0,255,0], 0b0001, 0b0011); // white break; case 38: SPI2.send4bit([20,0,0, 20,0,0, 20,0,0, 20,0,0, 30,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 39: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 40: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 41: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 42: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 43: SPI2.send4bit([10,0,0, 10,0,0, 10,0,0, 10,0,0, 10,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 44: SPI2.send4bit([50,0,0, 100,0,0, 150,0,0, 200,0,0, 50,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 45: SPI2.send4bit([155,50,0, 100,0,0, 150,0,0, 200,0,0, 50,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 46: SPI2.send4bit([50,0,0, 155,50,0, 150,0,0, 200,0,0, 50,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 47: SPI2.send4bit([50,0,0, 100,0,0, 155,50,0, 200,0,0, 50,0,0, 0,255,0], 0b0001, 0b0011); // white break; case 48: SPI2.send4bit([50,0,0, 100,0,0, 150,0,0, 155,50,0, 50,0,0, 255,255,255], 0b0001, 0b0011); // white break; case 49: SPI2.send4bit([50,0,0, 100,0,0, 150,0,0, 200,0,0, 155,50,0, 0,255,0], 0b0001, 0b0011); // white break; case 50: SPI2.send4bit([50,0,0, 100,0,0, 150,0,0, 200,0,0, 50,0,0, 255,255,255], 0b0001, 0b0011); // white break; default: SPI2.send4bit([50,0,0, 100,0,0, 150,0,0, 200,0,0, 50,0,0, 0,255,0], 0b0001, 0b0011); // white } global[1] += 5; global[2] += 2; global[4] += 1; } function noMail(){ if(global[3] > 5){ global[3] = 0; } if (global[4] !== 0){ switchit(); global[4] = 0; switchit(); } if(global[1] > 255){ global[8] = 0; global[1] = 255; } if(global[1] < 0){ global[8] = 1; global[1] = 0; } if(global[5] > 255){ global[6] = 0; global[5] = 255; } if(global[5] < 0){ global[6] = 1; global[5] = 0; } if(global[2] > 255){ global[7] = 0; global[2] = 255; } if(global[2] < 0){ global[7] = 1; global[2] = 0; } if(global[9] > 100){ global[10] = 0; global[9] = 100; } if(global[9] < 0){ global[10] = 1; global[9] = 0; } if(global[13] > 1000){ global[13] = 0; if (global[12] === 0){ global[12] = 1; } else { global[12] = 0; } } if (global[12] === 0){ switch(global[3]) { case 0: SPI2.send4bit([global[2],global[1],global[5], 0,0,global[9], 0,0,global[1], 0,0,global[9], 0,0,global[1], global[1],0,0], 0b0001, 0b0011); break; case 1: SPI2.send4bit([25,25,global[1], global[2],global[1],global[5], 0,0,global[1], 0,0,global[9], 0,0,global[1], global[1],0,0], 0b0001, 0b0011); break; case 2: SPI2.send4bit([0,0,global[1], 25,25,global[9], global[2],global[1],global[5], 0,0,global[1], 0,0,global[1], global[1],0,0], 0b0001, 0b0011); break; case 3: SPI2.send4bit([0,0,global[1], 0,0,global[9], 25,25,50, global[2],global[1],global[5], 0,0,global[1], global[1],0,0], 0b0001, 0b0011); break; case 4: SPI2.send4bit([0,0,global[1], 0,0,global[9], 0,0,global[1], 25,25,global[9], global[2],global[1],global[5], global[1],0,0], 0b0001, 0b0011); break; default: SPI2.send4bit([0,0,global[1], 0,0,global[9], 0,0,global[1], 0,0,global[9], 25,25,global[1], global[1],0,0], 0b0001, 0b0011); } global[3] += 1; } else { SPI2.send4bit([global[1],global[5],global[9],global[5],global[2],global[1],global[5],global[1],global[2],global[5],global[2],global[1],global[1],global[5],global[9],global[9],0,0], 0b0001, 0b0011); } global[13] += 1; if (global[6] == 1){ global[5] += 1; } else{ global[5] -= 1; } if (global[7] == 1){ global[2] += 2; } else { global[2] -= 2; } if (global[8] == 1){ global[1] += 5; } else { global[1] -= 5; } if (global[10] == 1){ global[9] += 10; } else { global[9] -= 10; } } function blackOut(){SPI2.send4bit([0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0], 0b0001, 0b0011);} running = setInterval(runIt, 200); setWatch(switchit, BTN1, {repeat:true, edge:"rising"});
-
-
I had a lot of issue getting the drivers to work on windows 7 64. Even now the IDE does not show debug output but at least I can push to the espruino.
Use the instructions Gordon has supplied - however you will have to go in to device manager and access the "drivers" tab for the unknown com device and manually point to the file that is unzipped with the driver download, it was greyed out for me when I tried to update drivers via the "devices and printers" window.
-
@gordon well I blew up my emitter!
A capacitor exploded in the emitter while I was testing the DMX signal, it didn't simply pop its top, it blew in to pieces!
I am not sure if it was a fault with the emitter or if the DMX shield sent enough current to overload the capacitor, I tested it with tx to tx first, and was not seeing any results, so I switched it over to RX on the shield, was playing around in the IDE and BOOM.
When I measure the pins in the DMX shield it seems to be putting out half a volt consistently flowing from the bottom pin to each of the top pins (3 pin DMX) while plugged into RX on the shield
When plugged into TX on the shield it reads .08v flowing in the other direction.
I cant seem to measure any amps when I test with the multimeter in either configuration however, which seems weird to me, though I am no electronics guru.
Think it was the negative voltage flow that killed it? I would be cautious to try again as these emitters are not cheap.
It is a pity that DMX shield has no documentation, otherwise it would not be such a guessing game.
-
-
Thanks @Gordon.
I guess I will have to experiment to find out what sort of input the emitter expects, I have a feeling that using:
Serial1.write([255,255,255]);
is not going to yield the same results as the RGB strips, I am sure DMX will be more complicated than this?
-
Thank you @DrAzzy!
I will Use the same pins on pico
I will try RX to RX first
I will use BAT_IN for pico powerThat just leaves:
How do I send Uint8Array(512) RGB data to a specific DMX channel
-
@Gordon @allObjects I was hoping to borrow some more of your knowledge.
I have finally received my DMX shield, it got caught in customs it seems.
I may need a push in the right direction on how to wire it up to my project. I have decided to use a pico instead now because of size in the enclosure I have (assuming it is up to the job).
As far as I can see I should be able to use mostly the same pins on the pico as the full size espruino:
For HC-SR04 Ultrasonic Sensor x3
Espr --- Pico
A0 ---> A0 (trig)
A1 ---> A1 (echo)
A2 ---> A2 (trig)
A3 ---> A3 (echo)
A4 ---> A4 (trig)
A5 ---> A5 (echo)Now I need to replace the Serial port which I was using for the RGB strip with USART_RX & USART_TX:
PICO
B6 --- Transmit
B7 --- ReceiveThese need to be hooked up to the DMX shield, I assume like so:
PICO --- DMX
B6 --- RX 0
B7 --- TX 1
(assuming RX on PICO goes to TX on the shield and vice versa, or do I have that backwards)I then need to work out how to send the data as Uint8Array(512) instead of send4bit, I am not sure on this part.
And then finally, there is the power. I have a 5v 3a power supply, I assume that this should be able to power the pico and the shield together (though I am unsure of the current pulled by the DMX shield). The shield has a 5v pin, so that should be easy, however I am not certain I can put 5v straight to the pico without blowing things up, am I save to plug 5v into the pico 3.3 pin or do I need to step it down first?
Finally I can connect all of the grounds together and cross my fingers she works.
Can one of you guys confirm I am on the right track, I appreciate your time.
Summary:
- Will A0 to A5 on pico work the same as A0 to A5 on Espruino?
- Will RX on pico goes to TX on the shield, or does RX on pico go to RX on shield
- How do I send Uint8Array(512) RGB data to a specific DMX channel
- Can I safely put 5v 3a direct to pico?
Reference:
DMX Shield: https://www.tindie.com/products/Conceptinetics/dmx-shield-for-arduino-remote-device-management-capable/ - I cant seem to find any diagrams docs on the shiend
PICO: http://www.espruino.com/Pico
ESPRUINO: http://www.espruino.com/EspruinoBoard - Will A0 to A5 on pico work the same as A0 to A5 on Espruino?
-
-
working with a greater distance, firing sensors individually, more stable output:
var distanceR = 0; var distanceG = 0; var distanceB = 0; var running; var c=0; var sensorR = require("HC-SR04").connect(A0,A1,function(dist) { if (dist < 300 && dist > 0) distanceR = dist; }); var sensorG = require("HC-SR04").connect(A2,A3,function(dist) { if (dist < 300 && dist > 0) distanceG = dist; }); var sensorB = require("HC-SR04").connect(A4,A5,function(dist) { if (dist < 300 && dist > 0) distanceB = dist; }); SPI2.setup({baud:3200000, mosi:B15}); function runIt(){ if (c===0) sensorR.trigger(); if (c===1) sensorG.trigger(); if (c===2) { sensorB.trigger(); sendToLeds(); c=0; } else c++; } function sendToLeds(){ //console.log("before("+Math.floor(distanceR)+","+Math.floor(distanceG)+","+Math.floor(distanceB)+")"); if(distanceR > 100 || distanceR === 0){distanceR = 0;} else {distanceR = 255-(distanceR/4)*10;} if(distanceG > 100 || distanceG === 0){distanceG = 0;} else {distanceG = 255-(distanceG/4)*10;} if(distanceB > 100 || distanceB === 0){distanceB = 0;} else {distanceB = 255-(distanceB/4)*10;} if(Math.floor(distanceR) > 0 || Math.floor(distanceG) > 0 || Math.floor(distanceB) > 0) console.log("RGB("+Math.floor(distanceR)+","+Math.floor(distanceG)+","+Math.floor(distanceB)+")"); SPI2.send4bit([distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB], 0b0001, 0b0011); // white } function stopIt(){ console.log("button pressed"); clearInterval(running); } running = setInterval(runIt, 100); setWatch(stopIt, BTN1, {repeat:true, edge:"rising"});
-
-
Any of these left @Gordon? I am going to have to make an order soon and wouldn't mind trying the pico
-
Here is a good tutorial on what to do once you procure a box from the hardware store:
http://www.instructables.com/id/Building-an-Electronics-Enclosure/ -
In Australia, looks like we have a decent selection at our chain hardware store
http://www.bunnings.com.au/our-range/lighting-electrical/electrical/powerpoints-light-switches-accessories/junction-boxes -
Hi all,
Thanks to the helpful people on this forum I am now at the stage that I am looking on building a finished product from my project.
I will need to have some sturdy casing for my gadgets, one for the main unit and three to house my sensors (HC-SR04), the sensors will need to have pluggable 4 core, 1.5 meter cables and will need to have a face that does not shield the sensors but (somewhat) hides them from view and protects them from the elements (I am hoping a thin mesh material will do the job).
I will also need to be able to secure the cases by bolting them to something as this will be in a public area.
Being my first project, I have no idea where to look for casing, so I thought I would ask the community, is there a good site to get generic plastic cases from, or do people usually make their own cases?
-
@Gordon I have had that issue, that is a nice solution to it, though the crossover does produce a pretty lighting effect :)
I think having each sensor with a 1 meter gap between should help with the issue also, for the end result three people moving through the installation should be able to produce any color / shade on the RGB scale, can't wait to go full scale.
-
Using 3 sensors, one for red, one for green, one for blue. Measuring up to 25 cm (full scale will be 2.55 meters) otherwise set levels to 0
var distanceR = 0; var distanceG = 0; var distanceB = 0; var running; var sensorR = require("HC-SR04").connect(A0,A1,function(dist) { distanceR = dist; }); var sensorG = require("HC-SR04").connect(A2,A3,function(dist) { distanceG = dist; }); var sensorB = require("HC-SR04").connect(A4,A5,function(dist) { distanceB = dist; }); SPI2.setup({baud:3200000, mosi:B15}); function runIt(){ sensorR.trigger(); sensorG.trigger(); sensorB.trigger(); console.log("RGB("+Math.floor(distanceR)+","+Math.floor(distanceG)+","+Math.floor(distanceB)+")"); if(distanceR > 25){distanceR = 0;} else {distanceR = distanceR*10;} if(distanceG > 25){distanceG = 0;} else {distanceG = distanceG*10;} if(distanceB > 25){distanceB = 0;} else {distanceB = distanceB*10;} SPI2.send4bit([distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB,distanceR,distanceG,distanceB], 0b0001, 0b0011); // white } function stopIt(){ console.log("button pressed"); clearInterval(running); } running = setInterval(runIt, 100); setWatch(stopIt, BTN1, {repeat:true, edge:"rising"});
-
Thanks @Gordon I will order that shield now and update when I have progress
-
@Gordon yes this is to send DMX signals, no need to receive. I was looking into the protocol, it seems to need a serial outpit and a set of data not dissimilar to what is sent to the RGB-LED's I have been playing with.
I am not sure what could be used on the espruino to create a serial connection, plus the need for a three pin connector I figured a shield may be the way to go.
-
@Gordon would something like this work with espruino? https://www.tindie.com/products/Conceptinetics/dmx-shield-for-arduino-remote-device-management-capable/
-
@allObjects the aim is for an on-street interactive lighting installation for our local council, so the sensors would be strategically placed to pick up people moving through the installation and affecting the lighting around them (the lights will go back to a default routine when no one is within range). We needed some pretty powerful emitters to put through fibre optic cables and the ones available need to be controlled via DMX, otherwise the prototype I have would almost be sufficient as is.
-
@allObjects I have my RGB strip powered off of 5VDC regulated which can supply up to 3amps which is plenty for this initial prototype (24 LED strip).
That multiple button script will definitely come in handy. My next bit of research is going to be into getting a DMX protocol working so that I can power four emitters in a DMX chain. Does not look like there is too much out there in javascript (I saw something using node).
I have a video which is being uploaded to youtube I will post it here when it has finished processing.
I have been tasked to come up with a novelty light which will switch on or off when the housing is slapped.
I will need a fairly sensitive shock/vibration sensor to do the job, can anyone suggest a component that will do the job and is compatible with the espruino?