-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Pro Mini Extender #1
Comments
Where can i find instructions about creating and programming the Pro Mini? Without a working PME, i can not start even... |
Here is the sketch I use with ESPeasy https://github.com/letscontrolit/ESPEasySlaves/tree/master/MiniProExtender I has not been updated since long time but it works fine with esp8266 using ESPeasy software with above plugin included. I use a custom sketch to do some extra task on Pro Mini as below. /********************************************************************************************************************\
#include <Wire.h> //int POT_pin = A0; // Pot for testing the dimming int freqStep = 65; // or 78 based on power supply : This is the delay-per-brightness step in microseconds. // To calculate freqStep you divide the length of one full half-wave of the power #define I2C_MSG_IN_SIZE 4 #define CMD_DIGITAL_WRITE 1 volatile uint8_t sendBuffer[I2C_MSG_OUT_SIZE]; void setup() pinMode(triac1, OUTPUT); // Set the Triac1 pin as output pinMode(LED, OUTPUT); // Set the LED pin as output attachInterrupt(0, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection /* ****************************************************************************************************************** const int currentPin = A0; // ADC pin used for ACS712 const unsigned long sampleTime = 100000UL; // sample over 100ms, it is an exact number of cycles for both 50Hz and 60Hz mains void zero_cross_detect() { // writing pins is like 10 times faster if } // Turn on the TRIAC at the appropriate time
} void loop() {
//dim = dim / 8; // set dimmer value to global integer dim /* Serial.print("triac1 = "); Serial.print(triac1); delay(1000); unsigned long currentAcc = 0; while (count < numSamples) { float rms = sqrt((float)currentAcc/(float)numSamples) * (27.03 / 1024.0); // see note above for this 27.03 value / void receiveEvent(int count) void clearSendBuffer() void requestEvent() |
As you can see I am using Pro Mini for Mains current measurement and AC dimmer control which are impossible using only RPI or ESP8266. Thanks |
I found this on ebay, according to its description it is an AT Mega328 3.3V compatible with Pro Mini, i can order this if it will be sufficient to test: |
I followed user Costo's post on ESPeasy forum to understand how to read values from Pro Mini into ESPeasy. Basically he set up devices in ESPeasy on devices tab to read value from Pro Mini.Link is below https://www.letscontrolit.com/forum/viewtopic.php?f=4&t=627&p=6385&hilit=pme#p6385 |
So basically we can use Dummy devices to hold values and create one (or more) ProMini devices, in which to be given the destination task and value number(s) (max 10 row per dev?) with type (analog/digital)? I've done something similar (value rerouting) with battery value watching, which can be setted in Advanced settings. (i am using an ADS1015 for this goal now) The "compatible" device i mentioned in the previous post is right? |
Yes device you chose should work fine. For that matter any arduino device should work fine with shift register for 5V device or directly without shift register for 3.3V device. Your device is 3.3V so it should be fine by connecting directly 4 wires (3.3V, GND, SCL & SDA).To store value to dummy device you can use rules if it is implemented in your code. |
You will also need FTDI adapter to upload the sketch to Pro Mini like below Arduino Uno has this usb to serial chip built in but Pro mini does not. I live in USA and if you need Pro Mini , FTDI adapter and some extra sensors I have I can send them to you. Please let me know. Thanks |
Thanks, but I already have a CP2102 (for flashing Sonoff devices) i think it will work for uploading, and ordered a ProMini for testing. Itt will arrive in time.. If you want to send some other sensors which is currenty not supported, itt will be nice.. but i am living in Hungary, Europe. :) |
I was reading and tried to interpret the PME code. But i found a possible issue: It's default address 0x7f is outside of the valid I2C range. (0x08-0x77) |
Is it not possible to define different address within the range (0x008-0x77) in PME plugin and match same newly defined address in pro mini extender code on arduino ? While searching web I found following links https://www.raspberrypi.org/forums/viewtopic.php?t=155389 |
Yes, it is absolutely possible, but every PME needs to be reflashed with the recompiled sketch. :) I prefer 0x3F for the new address as this is the valid counterpart for 0x7f in 7bit. |
Thank you for start on PME plugin. Can't wait to test once it is implemented. |
Experimental version added at b0ca949 |
I started testing this plugin and following is my feedback -
When joystick down - 22:27:46 Event: PMEanalog6#Value=0.0 When joystick in middle - 22:27:50 Event: PMEdigital9#Value=255.0 When joystick up - 22:27:55 Event: PMEanalog6#Value=1023.0 22:28:00 Event: Clock#Time=Thu,22:28
22:31:52 Event: PMEdigital9#Value=149.0 If I move joystick sideways on both ends it seems there is no effect and values in log remain same as if joystick is middle position. For output side if at least 1 device is enabled (for reading pin value from pro mini ) then both extpwm & extgpio works fine and turn pin high or low when I issue extpwm or extgpio command from advanced tab of rpieasy. But in original espeasy there was no need to set up pme plugin on device page in order to enable extgpio and extpwm command. Output side worked automatically without setting up anything on device page for pme plugin. It is very good start and I appreciate your efforts. Thanks |
On further testing I realised that I was using 1 second interval on device page for all 3 pins so i changed interval to 2 seconds on 2 analog pins ( analog 6 & analog 7 ) and then it works reliably as it should. For digital pin 9 on pro mini no matter what interval I set on device page it shows value of 255 but it should be 1 or 0. sorry for confusion. Is it possible to change this behavior so that when switch is pressed or released on pin 9 it send data instantly to rpi instead of waiting for 60 seconds ? |
Thanks for testing. I am not familiar with the Arduino side of the ProMini, pin number 9 is just forwarded as it written in the text box to the ProMini. |
Thank you for your clarification on switch plugin. I will have to test more to see if there can be something done on pro mini code. |
@happytm: |
I tried new plugin -
|
I used joystick directly because pro mini i always use is 3.3v version (8mhz) the one I sent you is 3.3v so no need to have level shifter. The programming board also is set on 3.3v via jumper. I do not populate 6 pins on edge of pro mini to program it but just use holes and hold it tight with ftdi adapter while loading the program and it works. For my tests I used analog pins A6 & A7 for joystick. |
Thanks! I rewrite the MiniProExtender sketch, relocated the slow analogread() function from the ISR into the loop, i will test it with the joystick and let you know the results. |
I think with commit e2eebc4 i reached end of the road. There are nothing more i can do with the original PME sketch, approximately 1hour of continous reading can be achieved maximum, before PME I2C receiver function fails, and only power cycling can fix it. |
Thank you for all your efforts on this plugin. I tested it last night for few hours and it was working finefor general input output control from rpieasy. I still will be using original sketch from espeasy for my project with your original plugin from few days ago that was working fine except analog read which I do not need.My project need to control 6 digital pins on promini and I am not controlling it directly but sending extpwm commands for each 6 pins of promini via rules and at pro mini I am storing it into 7 integers (1 for pin number & 6 integers for pwm values to further process in a sketch on promini without triggering pins at pro mini. like below: case CMD_ANALOG_WRITE: I tried to store values to integers from your new pro mini sketch but I was unable to do so. At some point you can look into serial interface to pro mini instead of using I2C. I am not sure there is any code in espeasy for that. Thanks again. |
The serial plugin is also under development, i ran some multithreading related problems with that. I will try the analog_write hacking, if analog_write worked previously than this also hast to work. But your sketch in the first post will not work in this form, than it contains a delay() in the loop section, which will effectively kill the whole I2C processing. |
Oh that's a good news. |
Could you send the sketch you are using, without the unnecessary portions/comments? The one that you included in the first post, has some errors with comments and something is missing, as number of "}" is not ok. The section that calculates ESPrms is commented out, isn't it necessary? |
I am sorry I am not a programmer so I must have messed up somewhere. but following is user Costo's original sketch I am trying to use for promini: /********************************************************************************************************************\
#include <Wire.h> #define I2C_MSG_IN_SIZE 4 #define CMD_DIGITAL_WRITE 1 volatile uint8_t sendBuffer[I2C_MSG_OUT_SIZE]; void setup() /* ****************************************************************************************************************** const int currentPin = A7; // ADC pin used for ACS712 void loop() while (count < numSamples) float rms = sqrt((float)currentAcc/(float)numSamples) * (27.03 / 1024.0); // see note above for this 27.03 value void receiveEvent(int count) void clearSendBuffer() void requestEvent() Also for AC dimmers I wanted to use this original sketch which is below.I was trying to use input from RPIEasy and save it into integers at pro mini and then use those values to fire triacs. : /* Ryan McLaughlin ryanjmclaughlin@gmail.com The hardware consists of an Triac to act as an A/C switch and Thanks to http://www.andrewkilpatrick.org/blog/?page_id=445 /* to use the AC line frequency (half-period) as a reference point */ int dim1; // Dimming level (0-128) 0 = on, 128 = 0ff int triac1; // Output to Opto Triac1 // General #define I2C_MSG_IN_SIZE 4 #define CMD_DIGITAL_WRITE 1 volatile uint8_t sendBuffer[I2C_MSG_OUT_SIZE]; void setup() { // Begin setup void measure_half_period() { void zero_cross_detect() { // function to be fired at the zero crossing void fire_triacs() { // Called every DimStep (Timer1 interrupt, checks FireTriac[n] and fires if it's time void loop() { // Main Loop //FireTriac[2] = (DimRes * analogRead(2)) / 1024; // Read input and calc the next triac fire time void receiveEvent(int count) void clearSendBuffer() void requestEvent() I also is planning to use following rules in RPIEasy Rules tab and I tested it with pro mini with your original Promini plugin and it was storing dimmer values and triac value in integers at pro mini fine. 4 AC dimmers with 8 (128 x 8 = 1024 ) dimming level control menu for Raspberry pi using apds9960 gesture sensor with pro mini extender plugin on pi and slave code on pro minion 9960#Gesture do on dimmer#pin do endon on dimmer#dimvalue do endon Following are rules I use for esp8266 (espeasy) device for control using MPR121 sensor: 4 channel dimmer control on key#press=17.00 do // MPR121 up key press for dimmer 1 on key#press=272.00 do // MPR121 down key press for dimmer 1 on key#press=34.00 do on key#press=544.00 do on key#press=68.00 do on key#press=1088.00 do on key#press=136.00 do on key#press=2176.00 do on dimmer1 do // when http://192.168.0.73/control?cmd=event,dimmer1=100 command issued from browser on dimmer2 do on dimmer3 do on dimmer4 do I hope this is not too confusing. Thanks. |
It was a great challange to me, but now they compiles at least... |
I tested your sketches but did not work for me so I created following sketch & used latest plugin which work perfect for me. I think finally you have resolved this issue . I watched serial console on pro mini and it is changing integer values properly. Also I was getting proper values in to rpieasy for 3 analog values from pro mini. I very much appreciate your effort. Also can you commit following sketch for future reference before I mess it up again. /********************************************************************************************************************\
/* Updated by Robert Twomey rtwomey@u.washington.edu Changed zero-crossing detection to look for RISING edge rather Also changed the dim_check() to turn on the Triac, leaving it on Ryan McLaughlin ryanjmclaughlin@gmail.com The hardware consists of an Triac to act as an A/C switch and Thanks to http://www.andrewkilpatrick.org/blog/?page_id=445 */ #define I2C_MSG_IN_SIZE 4 #define CMD_DIGITAL_WRITE 1 //volatile byte I2CReceived = 0; //volatile int value = 0; int triac; volatile int i=0; // Variable to use as a counter int triac1; // Output to Opto Triac1 int LED = 10; // LED for testing int dim1; // Dimming level (0-128) 0 = on, 128 = 0ff int freqStep = 65; // or 78 based on power supply : This is the delay-per-brightness step in microseconds. // To calculate freqStep you divide the length of one full half-wave of the power void setup() pinMode(triac1, OUTPUT); // Set the Triac1 pin as output pinMode(LED, OUTPUT); // Set the LED pin as output attachInterrupt(0, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection /* ****************************************************************************************************************** const int currentPin = A0; // ADC pin used for ACS712 void zero_cross_detect() { // writing pins is like 10 times faster if } // Turn on the TRIAC at the appropriate time
if(i>=dim5) {
} // void handleI2C() void loop()
//dim = dim / 8; // set dimmer value to global integer dim Serial.print("dim = "); //Serial.print("triac = "); Serial.print(" t1 = "); // Serial.println(" ESPrms = "); delay(10000); } void receiveEvent(int count)
} void clearSendBuffer() void requestEvent() Thank you. |
I can add it, but this sketch is using the same old I2C handling, which can lead a lockup because analogread() function located are in the receiveEvent block which is an ISR function. I am afraid that after several hour it will come about. |
Uploaded to https://github.com/enesbcs/ESPEasySlaves/tree/master/MiniProExtenderOACS |
Thank you for starting great concept. I am user of great Espeasy Software on esp8266 for long time. RPIeasy could be very useful if there is I2C bridge with arduino pro mini thereby getting rid of some limitations of RPI. Whatever RPI can not do should be done by Pro Mini.
Thanks for great start.
The text was updated successfully, but these errors were encountered: