How To Build a Flashlight With Perfect Modes (picture heavy)

Welcome to the club, shingo!

Hi, zeremefico!
It’s all in the programming environment (tool-chain “Win-AVR”) pre-determined in Tido’s package. If you look in the file “subdir.mk” you’ll find:

  1. Add inputs and outputs from these tool invocations to the build variables
    C_SRCS += \
    …/driver.c

This means that the source file (driver.c) is placed one directory UP.
The invocation of the compiler is done by “makefile” (called by “make”).
I use a .bat-file “build.bat” (is in my zip-package) placed in the “simple” dir. It has three lines:

call make clean #this ensures that everything will be re-compiled.
call make all #this compiles all
pause #this is to keep the DOS-window (result) on the screen.

I hope this helps.

There was no new posts for a long time here!!!
Let’s change that :slight_smile:

Can THIS be used for burning new sw in fl. drivers?

At first pass it looks like it might work, but you would need to make an adapter from the 10-pin adapter to the 6-pins you need to program the board:

- VCC

- GND

- MOSI

- MISO

- SCK

  • RST

Will

but that adapter is just a simple cable since 4 pins @ the bottom side of that board are GND and ther’s one more from top side that is excess: NC ?
I think I’ll try out how it works, once it arrives J)
O, and another disadvantage is that it only works with Atmel MCU’s and not the Microchip PIC’s at the same time :frowning:

Yes, not that complicated to do - the adapter should be fairly straight forward to do.

Will

I found another interesting thing> LINK already has a 6-pin connector :slight_smile:

Hi everyone,
Would it be possible for someone to show an example how to make strobe the third mode if modifying the driver.c file?

So, if you wanted 3 modes, lo, high, and strobe, would you change line 39 to:

#define NUM_MODES 3 // how many modes should the flashlight have (1-5)

And then do something with these lines?

#define MODE_LVL032 0x00, 0x0A, 0x00, 0x00 // .
#define MODE_LVL128 0x00, 0xAE, 0x00, 0x00 // .
#define MODE_LVL255 0x00, 0xFF, 0x00, 0x00 // highest possible level

I know that 0a, ae and ff are percentages. But if I want to replace ae with strobe, how would that be done and how would you determine which it would be? (police, beacon, etc.)

Also, if you wanted memory, would you just change this:

line #108 (activate nomemory as you don’t want to have memory):
#define NOMEMORY

to this:

line #108 (activate nomemory as you don’t want to have memory):
#define MEMORY

Is that how options are changed?

I appreciate very much any help or tips

How I open simple source files ? AVR studio can’t open that files

Create a new project, copy and paste the file content.

I just spent the last 6 hours attempting to reprogram my first Nanjg 105C. No luck.

I can’t get my USBASP V2.0 to connect to the chip.

I am using a SOIC8 clip, and I have rewired the connections properly (99% sure). I’ve quadruple checked my wiring, including using a DMM to check continuity, all the way to the programmer.

I tried setting the JP3 jumper, in case the chip was in low speed mode.

I tried using both 3.3v and 5v.

I retested the driver, and it still functions as normal.

When entering this:
avrdude -p t13 -c usbasp -n

All I ever get is this:
avrdude: warning: cannot set sck period. please check for usbasp firmware update
.
avrdude: error: programm enable: target doesn’t answer. 1
avrdude: initialization failed, rc=–1
Double check connections and try again, or use -F to override
this check.

avrdude done. Thank you.

Is it possible the chip is locked or something?

HELP!

O M G

I figured it out… as always with this type of thing, it’s something stupid…

BEWARE:
Do not leave any mode stars soldered to ground before attempting to program. IT WILL NOT WORK.

Ah… Which star was it btw? I thought that stars 3 and 4 wouldn’t disturb flashing as they are not needed for ISP.

I had star 3 soldered.

Also, I don’t know if this matters, but I had originally cut the trace from star 1 to ground as well, but did not resolder that, and it does see the chip now.

ALSO, I think I found an error in the wiring diagram listed on the wiki, although it must work either way. In the users guide for my USBASP, it lists pin 4 as “TXD”, not ground, as the wiki states. I just swapped pins 3 and 4 on my setup and it seems to work. (although I did try it the other way when having problems too)

So, now I’m stuck on a seemingly simple step… showing my newbieness, how do you compile the file, or whatever you call it, so I can use avrdude to flash it? I have it loaded up in AtmelStudio 6… but now what?

Well after a full day of frustration and tinkering, I have successfully installed new drivers on my first Nanjg 105C.

Unfortunately, the only way I could get it to work was with Tido’s .hex and .eep files for the existing versions. I have not been able to get a custom driver to compile properly… but tonight it is just way too late.

I tried the luxdrv, with no modifications changes, and it gave 5 errors when I attempted to build. I’m doing it wrong apparently. Is Atmel Studio 6 a little different maybe? Anyway, goodnight. I’ll try more tomorrow.

Yes, someone told me that, too. I still use AVR studio 4, it works with that. If I remember correctly, those errors can be easily fixed though. Please post the error message and the code line(s).

TXD and RXD refer to inofficial pins on the 10-pin ISP header; officially they are connected to Ground (4,6,8,10) and 3 is not connected. Some programmers use 4 & 6 to get a serial connection if wanted. The’re not connected to the ATiny anyway though. ATtiny pins 2 & 3 are not connected to the programmer.

When building luxdrv with Atmel Studio 6, I get this:

Error 1 Cannot find include file: avr/pgmspace.h 33
Error 2 PROGMEM: Unknown instruction or macro 43
Error 3 uint8_t: Unknown instruction or macro 43
Error 4 modes: Unknown instruction or macro 43
Error 5 syntax error, unexpected ‘=’ 43

Moving this to the luxdrv thread…

Currently i have succesfully programmed attiny13 with tido’s driver files to work as; no memory, extended modes, pin switch mode selection. I am happy so far as it is much much better than a standard driver but I want to learn more about the program.

I am trying to understand the general program flow to add a modification, but it is difficult for someone who is not proficient in C language.

This is the kind of thing i want to add to where the pwm level is set;

So i can have 2 amc7135 ic’s on pin6 as normal edc modes, but selecting high mode will turn on pin3 and switch on 6 more amc7135 for the full 2.8a turbo!. This would be better for my application rather than PWM’ing all 8 amc7135.

I see the various mode functions, and i think also how output pwm level is set via the line

but i dont understand what part of the program sets PWM_LVL or calls the sos functions.

There seems to be a pointer to eeprom addresses where the mode are stored but i cannot see where the eeprom is read and pwm_lvl is set, or functions are called, some pseudo code as to how tido’s program works would help immensely.

P.S. has anyone noticed the when in extended modes the light dims downwards before getting brighter? it might just be mine it had a lot of programs and abuse!

Fighting the battle against poor mode memory……………

I cannot compile anymore. What is going on here?

Task “RunCompilerTask”
C:\Program Files (x86)\Atmel\AVR Studio 5.1\make\make.exe clean all
rm -rf Test.o Test.d
rm -rf “Test.hex” “Test.lss” “Test.eep” “Test.map”
Test.cpp
Invoking: AVR8/GNU C Compiler
“C:\Program Files (x86)\Atmel\AVR Studio 5.1\extensions\Atmel\AVRGCC\3.3.1.27\AVRToolchain\bin\avr-g.exe” -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -MD -MP -MF “Test.d” -MT”Test.d” -mmcu=attiny13a -o”Test.o” “…/./Test.cpp”
In file included from …/./Test.cpp:10:0:
c:\program files (x86)\atmel\avr studio 5.1\extensions\atmel\avrgcc\3.3.1.27\avrtoolchain\bin\./lib/gcc/avr/4.5.1/…/…/…/…/avr/include/util/delay.h(89,3): #warning “F_CPU not defined for <util/delay.h>”
c:\program files (x86)\atmel\avr studio 5.1\extensions\atmel\avrgcc\3.3.1.27\avrtoolchain\bin\./lib/gcc/avr/4.5.1/…/…/…/…/avr/include/util/delay.h: In function ‘void _delay_ms(double)’:
c:\program files (x86)\atmel\avr studio 5.1\extensions\atmel\avrgcc\3.3.1.27\avrtoolchain\bin\./lib/gcc/avr/4.5.1/…/…/…/…/avr/include/util/delay.h(149,42): ‘fabs’ was not declared in this scope
c:\program files (x86)\atmel\avr studio 5.1\extensions\atmel\avrgcc\3.3.1.27\avrtoolchain\bin\./lib/gcc/avr/4.5.1/…/…/…/…/avr/include/util/delay.h(149,43): ‘ceil’ was not declared in this scope
c:\program files (x86)\atmel\avr studio 5.1\extensions\atmel\avrgcc\3.3.1.27\avrtoolchain\bin\./lib/gcc/avr/4.5.1/…/…/…/…/avr/include/util/delay.h: In function ‘void _delay_us(double)’:
c:\program files (x86)\atmel\avr studio 5.1\extensions\atmel\avrgcc\3.3.1.27\avrtoolchain\bin\./lib/gcc/avr/4.5.1/…/…/…/…/avr/include/util/delay.h(226,42): ‘fabs’ was not declared in this scope
c:\program files (x86)\atmel\avr studio 5.1\extensions\atmel\avrgcc\3.3.1.27\avrtoolchain\bin\./lib/gcc/avr/4.5.1/…/…/…/…/avr/include/util/delay.h(226,43): ‘ceil’ was not declared in this scope
make: * [Test.o] Error 1
Done executing task “RunCompilerTask” — FAILED.
Done building target “CoreRebuild” in project “Test.cppproj” — FAILED.
Done building project “Test.cppproj” — FAILED.

Build FAILED.
Rebuild All: 0 succeeded, 1 failed, 0 skipped

My guess is that you either deleted the “#define F_CPU 4800000” (Or similar) line in the source code (if there was one) or the CPU frequency setting in the project settings is missing.