-
-
-
Oli and Gordon, the way your wrote isn't working, OLED doesn't start after reset,
but MaBe advice looks like good one, OLED and all code is starting after reset, but EspruinoIDE return some error in console>echo(0); Erasing Flash..... Writing......... Compressed 81600 bytes to 6195 Checking... Done! Uncaught ReferenceError: "o" is not defined at line 1 col 1 o(1); ^
btw. is this save operation store some data on the MCU every save I make? I mean should I flash espruino to save space on the mcu or during save oparation it will erase all old data and replace them with new one?
-
is it possible to make for loop with some delay? I want to make an average sum for first few readings from ADS but for loop without delay between following readings pico return only 0 value,
when with the same code but analogRead function instead of ads read it works fine, maybe ADS need some time to send another value and for loop in espruino is to fast? some debounce kind operation is necessary? -
hi, I play now a couple hours with save and onInit function and can't run my program when my pico is starting after reset (unplug from usb), is there any simple explanation?
here is the codefunction oled(){ g.clear(); g.setFontVector(28); g.drawString("FIRST",0,12); g.flip(); setTimeout(function(){ nextOne(); setTimeout(function(){clear();},3000); setTimeout(function(){setInterval(data,1000);},3200); },2000); } function nextOne(){ g.clear(); g.drawString("NEXT",0,12); g.flip(); } function clear(){ g.clear();g.flip(); } function data() { var bat = analogRead(A5); g.clear(); g.drawString(bat.toFixed(2) + "v",0,0); g.flip(); } function onInit(){ setTimeout(function(){ oled(); },2000); // onInit(); } onInit(); I2C2.setup({scl:B10,sda:B3}); var g = require("SSD1306").connect(I2C2); E.on('init', function() { onInit(); });
-
-
-
-
thank you Gordon, it is working now, espruino is reading all channels and gain is working as well,
I can now move on and try to finish my project ;)do you know the way how to create new var value which will get readings from this ADS function?
ads.getADC(0, function(val0) {});
I have to do plenty of mathematical operations with my variable on few channels, it would be much simpler to use eg. var inputOne instead of this function above,
actually I can't print val0 outside the function, and I need to use readings from ADS in few steps, make a math and then print it,
I appreciate help in this case -
-
-
I still use 1v81 , now used this code
var CONFIG = { OS_MASK : (0x8000), OS_SINGLE : (0x8000), // Write: Set to start a single-conversion OS_BUSY : (0x0000), // Read: Bit = 0 when conversion is in progress OS_NOTBUSY : (0x8000), // Read: Bit = 1 when device is not performing a conversion MUX_MASK : (0x7000), MUX_DIFF_0_1 : (0x0000), // Differential P = AIN0, N = AIN1 (default) MUX_DIFF_0_3 : (0x1000), // Differential P = AIN0, N = AIN3 MUX_DIFF_1_3 : (0x2000), // Differential P = AIN1, N = AIN3 MUX_DIFF_2_3 : (0x3000), // Differential P = AIN2, N = AIN3 MUX_SINGLE_0 : (0x4000), // Single-ended AIN0 MUX_SINGLE_1 : (0x5000), // Single-ended AIN1 MUX_SINGLE_2 : (0x6000), // Single-ended AIN2 MUX_SINGLE_3 : (0x7000), // Single-ended AIN3 PGA_MASK : (0x0E00), PGA_6_144V : (0x0000), // +/-6.144V range = Gain 2/3 PGA_4_096V : (0x0200), // +/-4.096V range = Gain 1 PGA_2_048V : (0x0400), // +/-2.048V range = Gain 2 (default) PGA_1_024V : (0x0600), // +/-1.024V range = Gain 4 PGA_0_512V : (0x0800), // +/-0.512V range = Gain 8 PGA_0_256V : (0x0A00), // +/-0.256V range = Gain 16 MODE_MASK : (0x0100), MODE_CONTIN : (0x0000), // Continuous conversion mode MODE_SINGLE : (0x0100), // Power-down single-shot mode (default) DR_MASK : (0x00E0), DR_128SPS : (0x0000), // 128 samples per second DR_250SPS : (0x0020), // 250 samples per second DR_490SPS : (0x0040), // 490 samples per second DR_920SPS : (0x0060), // 920 samples per second DR_1600SPS : (0x0080), // 1600 samples per second (default) DR_2400SPS : (0x00A0), // 2400 samples per second DR_3300SPS : (0x00C0), // 3300 samples per second CMODE_MASK : (0x0010), CMODE_TRAD : (0x0000), // Traditional comparator with hysteresis (default) CMODE_WINDOW : (0x0010), // Window comparator CPOL_MASK : (0x0008), CPOL_ACTVLOW : (0x0000), // ALERT/RDY pin is low when active (default) CPOL_ACTVHI : (0x0008), // ALERT/RDY pin is high when active CLAT_MASK : (0x0004), // Determines if ALERT/RDY pin latches once asserted CLAT_NONLAT : (0x0000), // Non-latching comparator (default) CLAT_LATCH : (0x0004), // Latching comparator CQUE_MASK : (0x0003), CQUE_1CONV : (0x0000), // Assert ALERT/RDY after one conversions CQUE_2CONV : (0x0001), // Assert ALERT/RDY after two conversions CQUE_4CONV : (0x0002), // Assert ALERT/RDY after four conversions CQUE_NONE : (0x0003), // Disable the comparator and put ALERT/RDY in high state (default) }; var GAINS = { 6144 : CONFIG.PGA_6_144V, // +/-6.144V range = Gain 2/3 4096 : CONFIG.PGA_4_096V, // +/-4.096V range = Gain 1 2048 : CONFIG.PGA_2_048V, // +/-2.048V range = Gain 2 (default) 1024 : CONFIG.PGA_1_024V, // +/-1.024V range = Gain 4 512 : CONFIG.PGA_0_512V, // +/-0.512V range = Gain 8 256 : CONFIG.PGA_0_256V, // +/-0.256V range = Gain 16; }; var REG = { MASK : 3, CONVERT : 0, CONFIG : 1, LOWTHRESH : 2, HITHRESH : 3 }; function ADS1X15(i2c) { this.i2c = i2c; this.addr = 0x48; this.gain = 0; } ADS1X15.prototype.writeRegister = function(reg, value) { this.i2c.writeTo(this.addr, reg, value>>8, value); }; ADS1X15.prototype.readRegister = function(reg) { this.i2c.writeTo(this.addr, reg); var d = this.i2c.readFrom(this.addr, 2); return (d[0] << 8) | d[1]; }; /// set the gain, with a value in mv (6144, 4096, 2048, 1024, 512 or 256). The value is the full swing, so 256 = +/- 0.256v ADS1X15.prototype.setGain = function(gain) { if (!(gain in GAINS)) throw new Error("Gain "+gain+" not found"); this.gain = gain; }; ADS1X15.prototype.getADC = function(channel, callback) { var config = CONFIG.CQUE_NONE | // Disable the comparator (default val) CONFIG.CLAT_NONLAT | // Non-latching (default val) CONFIG.CPOL_ACTVLOW | // Alert/Rdy active low (default val) CONFIG.CMODE_TRAD | // Traditional comparator (default val) CONFIG.DR_1600SPS | // 1600 samples per second (default) CONFIG.MODE_SINGLE; // Single-shot mode (default) // Set PGA/voltage range config |= this.gain; // Set single-ended input channel config |= [CONFIG.MUX_SINGLE_0,CONFIG.MUX_SINGLE_1,CONFIG.MUX_SINGLE_2,CONFIG.MUX_SINGLE_3][channel]; // Set 'start single-conversion' bit config |= CONFIG.OS_SINGLE; // Write config register to the ADC this.writeRegister(REG.CONFIG, config); // Wait for the conversion to complete var ads = this; setTimeout(function() { // Read the conversion results // Shift 12-bit results right 4 bits for the ADS1015 callback(ads.readRegister(REG.CONVERT)); }, 8); }; // then try with I2C1.setup({ scl : B6, sda: B7} ); var ads = new ADS1X15(I2C1); ads.setGain(512); // +/- 0.256mV function everySecond() { ads.getADC(0, function(val0) { ads.getADC(1, function(val1) { ads.getADC(2, function(val2) { ads.getADC(3, function(val3) { console.log(val0,val1,val2,val3); }); }); }); }); } setInterval(everySecond, 1000);
and ADS shows me only one channel value, I've connected 3 voltage sources into it,
|_____|___| _|_| |___|_|_|_|___| |_| http://espruino.com 1v81 Copyright 2015 G.Williams >echo(0); =undefined 4531 75 79 78 4533 74 79 78 4580 75 79 77 4527 75 78 78 4622 75 79 78
I checked 3 other ADS, they are working on arduino, but here I get only one value,
could anyone help to fix it? pleasealso I am not sure about gain settings,
seems they have some error too, as eg. 256 gain shows lower value than 2048? -
-
-
Gordon, I'll checked that, values are still floating :(
maybe is possible to use average example code you wrote, and set something like permanent refresh of function which will count analog Value again and again from the start?
average function was very accurate on the beginning but not after a while, maybe is should reset old value and start with new one every let say 1000 ms? -
median filter from the code above Gordon is returning 0 value, could you fix it?
average way isn't correct after while, on the beginning values are corresponding to multimeter but after few minutes average isn't change as fast an as accurate as value on the multimeteraverage filter could be quite good if it could reset every some cycle of time and take fresh reading values for count
allObjects: your code is working but after setTimeout time I see both "waiting" and "CO2 measured..." commands - would like to leave only readings after 5min
-
-
looks very interesting, I would like to send from one espruino pwm signal to drive motor at other side (up to 1.5km away), trigger function would be necessary as if I push trigger harder would like to get faster speed of the motor and decrease it when trigger has low tension or switch off when the trigger is released
-
-
-
thank you will check that later on,
have another problem with this sensor,
when I connect it into multimeter it shows quite stable measurements,
when I blow on the sensor volts value is changing quite fluent,
but when I use espruino with analogRead function for this, and convert it into volts,
then my measurements are not stable, and are changing more than a little,
is any way to stabilize it? -
hi, haven't use yet Espruino timers, would like to make some command on the beginning for 5minutes and then read and print values from MG-811 sensor,
I want print "wait" on the console or display and when 5minutes times from the start will finish I want to Espruino start read the values from sensor and print these values instead of wait word
could someone help me with this? -
-
Hi, I've used code to run ssd1306 display from Espruino Web but it has some error
code I usedfunction start(){ // write some text g.drawString("Hello World!",2,2); // write to the screen g.flip(); } // I2C I2C1.setup({scl:B6,sda:B7}); var g = require("SSD1306").connect(I2C1, start);
error I've got
>echo(0); Uncaught InternalError: Timeout on I2C Write BUSY at line 1 col 19 {b.writeTo(d,[0,a])} ^ in function called from line 1 col 147 ...tion(a){b.writeTo(d,[0,a])});void 0!==c&&setTimeout(c,100);g... ^ in function "connect" called from line 1 col 47 var g = require("SSD1306").connect(I2C1, start); ^ =undefined >
anyone knows how to fix it?
hi, I wonder how to write some switch off/on function on my Espruino,
I use OLED ssd1306 and ADS1115 for low voltage readings and display them into OLED,
would like to switch off my Espruino for battery saving when I don't use it,
I know I can write some clear() function for OLED when I press button and send some low voltage for ADS vcc pin but maybe there is some simple solution?
is there any function I can use?