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
Software Serial #549
Comments
Also: this could be a way to get Serial that works from within deep sleep. |
Software I2C looks trivial, and could be implemented in the same way as software SPI. |
This UART will be good to implement to support http://wiki.iteadstudio.com/Nextion_HMI_Solution can somebody implement please? @tve maybe? :) |
I think we ought to have a bounty system. How much do you want it... enough to pay for the time we spend on it? :) |
Do it need to implement in javascript? If yes, then can u please help me to start it? (I promiss nothing, but maybe a try... I don't know how good now in low level things, this is why I like espruino couse its js :) and higher level language ) |
... bounty system... It is not bad idea... I am ready to contribute... You can try to begin the discussion in the News... but I have no idea about the total price for such task... |
Well, to do it properly you'll need to do it in C. However if you just want to send a few characters you can use JavaScript and digitalPulse, at least for stuff at slow-ish speeds like 9600 baud. All you need to do is keep the output at 1 usually, then you can use |
I think C is hard for me now. Here is some js implementation but it does not work yet. Thanks for yerpj user from gitter. Now I just send 'a' ascii char what i think is 01100001. what i get (the first array) (the comparable array is the second array): RX done. you got each bit in the RXByte array
[ 0, 0, 0, 1, 1, 1, 1, 1 ]
[ 0, 1, 1, 0, 0, 0, 0, 1 ] require("ESP8266").logDebug(false);
RX=new Pin(0); // ~D3 port;
//var bitTime=3.333; // for 300 BAUD
//var bitTime=1.666; // for 600 BAUD
var bitTime=0.833;//for 1200 BAUD
//var bitTime=0.104;//for 9600 BAUD
var bitCounter=0;
var RXByte=[];
var asciia=[0,1,1,0,0,0,0,1]; // for comparing with the sent a
var bitSampler = function(){
setTimeout(function(){
var currVal=digitalRead(RX);
RXByte[bitCounter]=currVal;
bitCounter++;
if(bitCounter==8)
{
bitCounter=0;
waitForFirstByte();
console.log("RX done. you got each bit in the RXByte array");
console.log(RXByte);
console.log(asciia);
}
else
bitSampler();
},bitTime);
};//a full bitTime to wait. See comment below
var waitForFirstByte = function()
{
setWatch(function(){
// console.log('falling down edge detected');
setTimeout(function()
{
var firstDataByte=digitalRead(RX);
RXByte[bitCounter]=firstDataByte;
bitCounter++;
bitSampler();
},bitTime/2);
//bittime/2 first, as you want to sample it at mid-time
},RX,{repeat:false,edge:'falling'});
};
waitForFirstByte(); what is wrong? :) Maybe @gfwilliams? :) |
Espruino isn't fast enough to use the timeout to poll. Try using setWatch. This works on an Espruino Pico, although it's not good at handling a whole series of bits - it's just too slow to process it. This is why you'd ideally handle it in C.
|
Full ready SW serial in C language for 8266 is here ... |
IMO it'd be much better if someone would actually just write this for Espruino. It'd then work for all Espruino devices, not just ESP8266. Same with I2C - there's a SW I2C implementation currently for ESP8266, but it's only for ESP8266 so it's useless for any other board that runs Espruino :( |
I absolutely agree... it would be really nice to have it (SW - I2C, SPI, serial) compatible on both platforms... but I am not able to write it 👎 |
I tested a RX method to recover each incoming byte. Current limitation: need about 6ms to compute the byte after EACH incoming byte.
Maybe this could help people willing to tinker with SW UART. |
If anyone wants to write a dedicated module for a SW UART, I would be pleased to contribute. However, as I am having holiday until february 27th (it means I would be AFK), I would help as soon as I come back. |
So was there some problem with the receive code that I posted up above? From the look of it, it probably needs less time per byte for calculations? |
Actually I did not see your implementation :-/ Otherwize I would not have taken time to write it by myself :-D @HyGy said that there weren't any implementation able to decode up to 9600 Baud, this is the reason why I tried to implement something. I was able to decode up to 115200 Baud (did not try faster Baudrate, as they are very unusual). That said, It seems that your implementation is efficient enough to support 9600 Baud. Did you already try? |
Sorry I missed this to, I'll test both now. But I think the best to implement it in c. But I cannot. :( |
Ahh, that's a shame. I was a bit surprised there was no response from @HyGy after I'd written it :) Yes, it'll do 9600, although IIRC maybe only a few characters one after the other. It needs some time to process things too. I guess the 'Compiled Code' could help with that. |
I tested @gfwilliams code first, from a separate USB ttl device. In one turn @gfwilliams code can receive 21 characters each other at 9600bps. In higher speeds the success caracters is less. |
@gfwilliams I connected the nextion display, it sends less bytes, so it seems it can work with this code. Now I need just the send code, and then I try to create a lib for this nextion display. |
You should be able to use I'd said elsewhere (it seems not on here) but there is now a branch for software serial in Espruino itself. It's not entirely working yet, but is a good start. Not sure when I'll get time to finish it though. |
@gfwilliams where can I watch this new implementation? |
Using the link above? That is the branch so any changes will appear on there. You can see what commits were made to see the changes I made. |
So I need to checkout the c source code, and compile it? |
Yes, or the latest binaries for the Espruino boards are here: http://www.espruino.com/binaries/git/commits/software_serial/ |
Got that branch, increase number of uart in the board file how to bind that uart to soft serial on esp ? |
It just jams the data into Serial6 at the moment. I think:
|
hmm, using this code on esp causes reboot as expected can get Serial2 by increasing the number of uarts in the board config file but no idea how to bind the serial code in jswrap_serial.c to that Serial2 on ESP |
Any update on this? I have 4.7k pullups on SDA and SCL, and have been trying numerous variations along this theme: I2C1.setup({scl:4,sda:5});
var wii = require("wii_nunchuck").connect(I2C1);
setInterval(function(){
console.log(JSON.stringify(wii.read()));
}, 2000); Dave |
my exports.connect = function(/*=I2C*/_i2c) {
var i2c = _i2c;
// initialise
i2c.writeTo(0x52, [0xF0,0x55]);
i2c.writeTo(0x52, [0xFB,0x00]);
// actual object
return { read : function () {
var d = i2c.readFrom(0x52, 6);
i2c.writeTo(0x52, 0);
// TODO: we could get another 2 bits of accelerometer data from d[5]
return { joy : {x:(d[0]-127)/128,y:(d[1]-127)/128},
acc : {x:(d[2]-127)/54,y:(d[3]-127)/54,z:(d[4]-127)/54},
btn : {z:!(d[5]&1),c:!(d[5]&2) }
};
} };
}; |
Based on the Espruino Design notes , I have pullups:
Based on Thorsten's advice from gitter, I've tried GPIO12/13: I2C1.setup({scl:12,sda:13});
var wii = require("wii_nunchuck").connect(I2C1);
setInterval(function(){
console.log(JSON.stringify(wii.read()));
}, 500); Based on this wii nunchuck blog I'm using 3.3V Not sure what else to try. |
I2C definitely works. It has some quirks, it may be too fast, etc. But I'm using it successfully with multiple devices. You're not providing any info other than "it doesn't work". Do you have a $10 logic state analyzer that you can hook up to record the i2c transactions? Or how about instrumenting the module to record which i2c transactions work and what responses they get? |
@tve sorry, I've been trying to debug in Gitter with MaBecker. |
Is this what you're referring to? or this: |
@tve after giving this issue of serial device connectivity more thought I'm thinking of going a different route. If we take a step back and look at this Serial connectivity issue more broadly, we have: So, at least for me, instead of learning how to debug using a logic analyzer etc., it makes more sense to accept that there is going to have to be some sort of Arduino device between the ESP and these serial devices. (basically an external version of the ESP-14). This would have several advantages:
So, this leaves the question of how best to network these devices. David update: looks like someone has already done a lot of work on the Arduino side: |
From the Espruino ESP docs it seems like SPI is the best available hardware-implemented serial protocol for used by Espruino on ESP-12 based boards.
So, that leaves SPI as the 'native' hardware-implemented serial protocol, no? |
A lot of people have had I2C working on ESP8266 - are you sure you have the right pins, as you seem to be using NodeMCU but just specifying the pins as numbers? You could use This bug really isn't the place to discuss reimplementing some firmata-style peripheral interface (or I2C connection problems for ESP8266) - maybe you could post on the forum? But if there is a problem with I2C, it's software so it should be fixable - trying to work around it by connecting another microcontroller seems like massive overkill when fixing the underlying problem is probably quite easy once we know what the problem is. |
I've tried many different combinations, e.g: D1/D2, which do you suggest?
Sorry about posting in the wrong place, the earlier comments on this issue reference several serial protocols (SPI, UARTs, pulsing digital IO, etc), so I got the impression that this issue concerned connecting ESP-8266 to various serial peripherals in general. My bad.
Sure, though one does wonder if the ESP-14 approach of adding an STM8 is indeed the best way to solve the problem. At least for me that would be an easier approach than learning how to use a logic analyzer! |
As long as you figured out that Problem is, instead of just using the Web IDE, then users have to install and learn the Arduino IDE, how to wire the 2 chips, and then also how to make an API to communicate nicely between the two. Suddenly instead of being nice and easy (if everything works) it turns into something very difficult. This bug was initially about adding software-based peripherals to Espruino itself (so shared between all boards) - although yeah, it has been driven by ESP8266 users who want extra communication ports. |
That part is still a bit confusing to me (i.e: the ESP8266 documentation, such as it is, is confusing), I tried all permutations - @MaBecker helped me significantly (much appreciated), and I'm sure that we are hitting the wii nunchuck peripheral.
True, but if it doesn't work, and you have 20+ quantity each of a couple dozen different peripherals already ordered, and a class of kids eager to use them all .... I ordered a Bus Pirate and also a logic analyzer to try and debug this. My gut still tells me that I'm going to end up ditching the software I2C, and bridging the hardware SPI to I2C at some point.
Got it, that explains my confusion, I thought this was ESP8266 specific. |
An i2c / logic analyser is pretty cheap and probably the best money you Ian. On 9 May 2016 at 14:26, davidmoshal notifications@github.com wrote:
|
@iharris Thanks Ian, a link to a good starting tutorial would be appreciated. Dave |
or not, just saying... |
Hi David, Funnily enough, there's not much do it. You connect the SDA/SCL pins to Hackaday shows the Salae analyser working here: Once you can see, for example, what address you're sending, and how the We had one our Embedded Adventures devices working on Arduino, but not on kind regards On 11 May 2016 at 01:50, davidmoshal notifications@github.com wrote:
|
Thanks Ian, much appreciated! |
Software I2C libraries are in there now. It's just serial to worry about |
Software serial is in too. Time to close? |
Thanks for the prod :) |
Shouldn't be too difficult, especially for lower baud rates. Software SPI is already there, and we can execute a user-defined function from inside a watch IRQ.
DrAzzy on the forums definitely wants it anyway.
The text was updated successfully, but these errors were encountered: