Can someone help me with some firmware please?

Hi all,

my efforts to write my own firmware stalled after I figured out how to flash a driver. That took all of my electronics gumption and now that the semester is in full swing I'm spending most of my waking hours teaching myself my courses that little bit faster than I'm teaching it to the students :)

So, I'm kind of stuck and I'd love a bit of help. I'd like a couple of different firmwares, one simple, one a bit more complicated:

- both for ATtiny13 driven 7135 based drivers

- both momentary switch (I've had endless problems with flakey Judco clickies)

- both with the usual voltage step down stuff at low voltage

- simple one is for a rear bike light. Needs to be on at 1/4 drive current and flash to full current, ideally a double flash like: low low low high low high low low low high low high low.. Toykeeper has an awesome version for clickies, but she said it would take a bit more work than she has time for swapping it over to momentary as it uses separate entries for each power level rather than one entry with multiple values like JonnyC's Starmom FW. Only really needs one mode, although another one at 1/2 (or 1/3 perhaps?) the drive current for each level wouldn't hurt if it's not too much work.

- more complicated one is for my front bike lights and could be a variant of JonnyC's Starmom FW, but with a short press moving up a level and a long press moving down. What would be really useful if there's a loop so that from low each short press moves up a level to high, then each short press cycles between med and high with a long press needed to get back down to low. Basically a Taskled Threemode mode :) Extra long press to turn off from current mode would be great (ie. no 0 PWM value as off, so I don't accidentally go through it on the trail).

No real need for blinkies, although I wouldn't say no to a hidden beacon as an emergency backup.

Something that would be totally awesome (again, like Taskled drivers) would be to have an intermediate voltage warning that dims the output (say to 1/4) a number of times when a voltage threshold has been reached. I have my Taskled lights set to ~3.6V from memory, which corresponds to ~45% remaining capacity. Annoyingly the Taskled version completely turns off the light in blinks, which can be a little hairy on a steep downhill if it's your only light!

Memory isn't all that important, especially if the light starts from low. Wouldn't hurt if it's not hard to do though.

Would anybody be able to modify one of the existing firmwares to do either (or both!) of the above? I would be incredibly grateful and I can't wait to fix my rear light as it's constantly on the verge of crapping out. I'm afraid I don't have anything to offer in exchange other than my eternal gratitude and tips on machining :)

Obviously any firmware would be the distributed as the writer sees fit, hopefully this may be useful to others in addition to myself.

Thanks!

That's exactly what mobydrv was designed for. Not free though.

yup, if I wasn't such a tightwad and obsessed with doing (most) things myself, that's exactly what I'd do :)

You say you are obsessed with doing things yourself, yet you are asking for help--not to debug code you've written or attempted to write, but basically to have someone make all of the modifications for you then hand you the code.

It seems like a bit of a contradiction. Am I missing something?

well I also wanted to modify just a bit here and bit there, but few months later I find myself writing new firmware for attiny85 because attiny13’s 1k is not enough :slight_smile:

i do have modified star momentary with moving forward and backwards through modes with short/long press. Perhaps you can start from there and modify it just a bit more to suit you.

RMM has said it nicely, so I’m just going to second his question.

Of course my advice is to purchase what you need. There are at least 2 good places to purchase DIY stuff for what you need: DrJones or TaskLED.

so that's a no then?

The contradiction is that I feel like I've helped a lot of people on here and I'm completely stumped by something I find very difficult, so I'm asking for help. I thought that as part of a larger community people would be willing to offer their help and by extension, help others that are in a similar situation. I thought that by getting a lift up and over that hump of understanding, which I just don't have to mental capacity to manage by myself, I would be able to continue on and perhaps contribute something similar myself.

It's like someone saying - I really need something made with a thread and I just can't figure it out myself, can someone make one for me to get me over my immediate need and show me so that I can teach myself, then perhaps figure it out and teach others? Or should I just be told - go do it yourself or pay to get it made?

I'm not asking anyone to write something from scratch (although you all seem fine with other people doing that for other members - did I phrase my request poorly?) more apply some tweaks that I don't know how to do to existing code. I've spent months poring through publicly available firmwares and I still don't have a clue how to do what I need. The irony is that it's taken weeks (if not months) to find the time (and courage!) to make this request. Sure I can buy stuff, but that would take money and that's something I don't have much to spare right now, for various reasons.

vex_zg, that would be a great help, thank you

We all like to share here, and we all like to help. It's a big part of why we're here. I like helping other people, and I benefit from what others post as well. I hope I am not coming across the wrong way, because I have certainly benefitted and learned a lot from everyone on this forum. There is no way I could have thought up or figured out all of the things I use and build on an daily basis on my own. I owe a lot of my knowledge and success to many here who have shared their thoughts, experiments, failures, and who have helped me with my various projects along the way.

There is nothing wrong with asking for help, but there is a big difference between asking for help with a project and asking for a handout. I'm not saying that asking for a handout is inherently wrong, because there are some here that like to take on difficult tasks both as a challenge to themselves and to help others, but you've got to be clear about what you are looking for. I think that is clear now.

There are some on here who would like to help you, I'm sure, but what you asked for is a pretty big undertaking and what you are looking for is complicated and very particular to you. Even for a competent coder, it is something that would take at least several hours worth of coding and debugging to get it running right.

It is a different story to say "I want to accomplish this specific task. This is the code I'm working with, this is what I've tried, this is where I'm stuck". Or, "I would like to add a specific feature to this firmware, can you help me? Where do I start?" If your goal really is to learn how to do it yourself, this is how it's done. I may be able to glean something from copying the answers to another student's math examination, but I won't truly learn it until I do it myself. Teachers, tutors, books, and other students are there to help with examples and to answer questions when you get stuck, but at the end of the process you will have learned it through going through the motions yourself.

What you asked for came across to me as this "I want two complex custom firmwares written for my very specific application. I have an immediate need for this firmware and need it fast. I am not willing to pay, but of course you can publish it if you'd like."

In summary, if your goal is to learn, we are always here to help with that, but it may not be fast or easy. Show us what you've tried and where you're stuck at.

that's fair enough RMM and I can see where I came across wrong. The trouble is I have no idea where to start. I've spent ages looking at Toykeeper's cool rear bike light firmware for clicky lights and at JonnyC's star momentary and I've no idea how to get from one to the other. It's like needing something translated but having to learn a whole language first. I don't even know what questions to ask. I even downloaded the ATtiny manual, but it makes no sense to me at all. Perhaps you're right, I should just give up and buy something, but neither of the offerings I particularly want (I bought one of DrJones' mobydrv drivers after helping him design the firmware and have never got it working right and I've used a ton of the Taskled drivers but can't afford them now).

I appreciate the value of learning by doing, after all I'm a professor so it's something I do every day :) I just can't seem to get beyond the basic electronics in the time I have available (couple of hours a week, shared with everything else I want to do).

So I'll see if Vex_zg's FW will do the trick and leave the other one as is.

BTW, the fact that DrJones has sold a few (how many we'll never know) of those mobydrv drivers, mostly on mountainbiking forums, and that Toykeeper is working on some firmware for other cyclists suggests that this isn't just for my benefit. That's just my perspective though.

Have a look at this minimalistic firmware by DrJones. It is well commented, so you should be able to get started: MiniDrv - simple firmware (source code)

I have to agree with the others… Writing firmware with semi-complex features takes time. People here are very helpful and share knowledge, but to be frank: you are asking for too much.

Nice try anyway. I might try offering to trade some hardware for the work. I don’t see a problem with bartering.

Thanks MikeC, it's obviously clear that I'm asking for too much given the responses although if I thought that any of the things I asked for were too much I wouldn't have asked for them. I was going by the responses others have had for similar requests (and the help I have had with other things) but clearly I am mistaken. I get the message.

I'll see what I can do with the firmwares posted up by others already and leave it at that.

I myself modified STAR momentary to do something similar to what you are asking for. Read this.

Edit: A link to a newer version of the firmware can be found here.

ToyKeeper mentioned that she has something similar in her repository.

I have since added a nice ramping feature with 19 brightness levels.

The fun and challenge of flashlight FW coding is to take someone else’s code that works but not exactly like what you want and then tweaking it to do what you want. The trap is that you are never completely happy with the UI and run out of code space and wishing that you can get another 1 KiB to add that one extra feature to make the perfect UI.

Once you get the firmware to do what you want, please return the favor and share the code with us.

thanks for the links dthoang, much appreciated. I've chatted with Selene a bit about the rear bike light code she's working on for clicky lights, but she's got a lot of other things on the boil right now.

I promise to share my progress, it'll most likely be a couple of years though.

Hi Matt, I don't work with AVR much so it would be an ordeal to write out the whole thing, but here's something that should help you get moving if you'd like to learn to do it yourself. Start by looking at my example code in this post: https://budgetlightforum.com/t/-/26378 That implements a basic light on ATTiny10 that uses a momentary switch. It should be easy to port it to ATTiny13 or another microcontroller. To add the strobe pattern you want, here's my method which uses a state machine and keeps everything clean, organized, and gives the processor plenty of time to perform other tasks (monitoring the button, voltage, etc.). Each of these sections go in a different spot in the code example linked above, it should be clear where each one belongs.

//add strobe to mode list, increase number of modes. 
//could make strobe and off the only modes if desired
unsigned char mode;
enum mode{
    max=0,
    med=1,
    low=2,
    strobe=3,
    off=4,
};
#define max_mode 4
//add a variable to maintain the state of the strobe pattern
unsigned char strobe_state;
//add a variable to time out the strobe pattern
unsigned int strobe_timer;
//add the countdown timer to the interrupt
if(strobe_timer){strobe_timer--;}
//add the strobe handler to the main loop
        if(state==strobe){  //only take action if in strobe mode
            if(strobe_timer==0){    //only take action if the last state finished
                strobe_state++;     //advance to the next state
                strobe_state&=0b00000011;   //limit the state value to four states
                switch(strobe_state){       //jump to the appropriate state
                    case 0:                     //state 0 - the long low time
                        pwm = 64;               //25%, change as desired
                        strobe_timer = 1000;    //1000ms, or one second of low output, change as desired
                        break;                  //done with this task
                    case 1:                     //state 1 - the first high time
                        pwm = 255;              //100%, change as desired
                        strobe_timer = 40;      //the blink duration. 40ms. change as desired
                        break;
                    case 2:                     //middle low period
                        pwm = 64;
                        strobe_timer = 80;      //80ms duration
                        break;
                    case 3:                     //second blink
                        pwm = 255;
                        strobe_timer = 40;
                        break;
                }
            }
        }

thank you tterev3, that is awesome, totally awesome and exactly what I was looking for! I'll find a basic momentary firmware (like minimo that has everything else I need) and stick it in there to see how it works.

If you add this to a different program instead of my example, be sure you have a timer source that can decrement the timer variable in the background. The 1kHz interrupt is something I always include in my code but it won’t be present in everyone’s

thank you, I was wondering about compatibility. I'll go read some of the others and get a sense of how they do things. Right now I'm must trying to learn and understand enough to be able to ask the right questions!

tterev3, thank you for sharing. I am not good enough to help much with firmware, although I have stumbled and fumbled my way into a few successful small modifications.