Hi guys, I have another quick question,

fastled-support
gplus
(Nicholas Tracy) #1

Hi guys, I have another quick question, I’m up and running with fast led and the 1284p. so ram and memory are not an issue as of yet. but i have a project that uses an enc28j60 ethernet module and an SD card to run a mini web server and udp listener. the udp listener works fine by itself with fast led and i use it to control patterns via my software. but after adding the web server and listening for a client each tick, the led strips are doing weird things. i am running 4 instances of fastled.
My question is, it here an ISR somewhere that could be slowing down fast led causing the weird laggyness of the strips? just using the UIPethernet library and the SD library.

(Daniel Garcia) #2

Hard to say without actually seeing your code (post to http://gist.github.com or pastebin, if you want to share it) - also hard to say without something more specific than “weird things” as a problem description.

If you are using WS2812 leds, however, be aware that writing out that LED data will disable the interrupts for as long as it takes to write out led data. This may cause problems for reading data, and if you’re using that read data to control the LEDs, weird things might start happening.

If the problem is just lag and slowing things down - i’d need to know more about what your web server is doing. i/o on the arduino isn’t exactly the fastest thing in the world. If you’re using the hardware SPI to send data to/from the enc28j60 - sending a full html page worth of data could easily take enough time to cause patterns to stutter (even more if you’re using software spi for talking to the enc28j60). Especially if your patterns are based on counters that increment every time through a loop, vs. being based on actual time passed.

(Nicholas Tracy) #3

Code isn’t really open source. I could try to post the snippets that I have borrowed that pertain to Fast led and the web server. however, I am using ws2812 strips at the moment. i have 4 instances. 4 outputs. enc28j60 is on hardware spi along with sd. CS pins are set and I made sure everything would play nice. up until i added the web server code it worked very smooth and udp commands streamed just fine, very responsive. now the web server code is not my own but has to call ‘EthernetClient client = server.available();’ every tick to check for incoming port 80 requests. I think this is where it lags the strip a little bit. (patterns and changes to color stutter noticeably.) because commenting this out makes things go fast again. is it possible that there is something in the Ethernet library that has some sort of delay for listening to incoming connections? it happens even if a browser hasn’t connected yet.
i know this isn’t really related to fast led but any ideas are very much appreciated.

(Daniel Garcia) #4

It is possible that there is something in the web server that is waiting and timing out - hard to say for sure without seeing the web server code.

(Nicholas Tracy) #5

Here is the Ethernet library being used https://github.com/ntruchsess/arduino_uip
Code snippet for web server.
http://pastebin.com/UxFMznhr
basically it just handles http requests and loads any requested files from the sd card. sd card is initialized in setup and there is an error handler for missing files and failed sd cards. nothing to out of the ordinary. haven’t looked through the library too much to see where the snag is at. thanks for looking. I appreciate the second set of eyes if you feel like taking a look.

(Daniel Garcia) #6

How large are the files that you are sending? Because while it is reading the file from sd card and writing the data out to the network it isn’t going to be doing anything else, and since both sd card and Ethernet are using the same spi hardware it can either read from sd card or write to the Ethernet device - I’ll have to do some more digging to see how efficient that is (newsflash - it is likely not efficient - hopefully it isn’t as bad as “read a byte from the sd card, write a byte to the Ethernet controller” - but it might be).

This might be a candidate for splitting into two MCUs, one to play web server and one to juggle LEDs and then use serial to send commands that may come in from the webserver over to the thing doing LEDs.

(Alternatively, make the reading/writing of data non blocking and interleaved with led writing - eg read some data from the sd card, run a frame of led data, write data from the sd card, run a frame of led data, etc…)

(Nicholas Tracy) #7

Makes sense, except from what i understood, the web server should be idle unless a connection to a client is established. even without connecting to the web port is lags a little. The index file itself is only 3k. I think the Ethernet library’s ‘EthernetClient client = server.available();’ call is causing the lag. somewhere in the library its doing a while loop or has a small delay to wait for incoming client connections. i think i’ll look there to see if maybe it can be trimmed down. i’m sure they designed it that way to prevent dropped or failed connections.

thank you for your help though sir, its much appreciated.

(Daniel Garcia) #8

Yeah - hard to say from just reading the code. What i’d need to do to really dig into this is getting it up and running, instrument the code a bit, and try to get actual timings.

Any chance you have a logic probe?

Because if you do, one thing that you can do is put code in at various places to raise/lower pins – then you can use the logic probe to see the actual timings of various functions. For example, a variation on something that I use for timing sections of code check out https://gist.github.com/focalintent/5da1daacfac2a75a84ae

This is a trick I use (I have a https://www.saleae.com logic pro 8) when I want to get timing of tight loops, or if i’m trying to see what’s happening where, and when, and why. It’s very very low overhead, but can make for very useful output.

(Also, as a side note, I’m a big proponent of measuring before going in and optimizing - whether measuring is doing something like this to get tight section timings, or doing a million loops of something with a stopwatch/millis() timer to get a sense of time cost, or sitting down with a glass of bourbon and a disassembly output and counting clock cycles by hand :slight_smile:

(Nicholas Tracy) #9

Thank your for the advice, I will try to cobble something together on my work bench later. I decided to forgo the web server fro now in favor of solely using a config file on the sd card. itll work for now until i figure out why the timings are off with the web server. So far it looks like there is a small delay when calling the function available() in the Ethernet library. don’t think i can get around it unless i rewrite the library somehow. maybe i’ll leave it for a bigger better processor, i’m eventually moving on to the ARM based chips. (i just got my SMD rework station in the mail today)