Writing to SD memory…

Soo… the latest update… I had wired in the SD memory stick reader and had been testing it separate from the main roaster program. I’ve found having a “dedicated” programs for a particular sensor with the rest of the sensors and displays attached but not initialized has resulted in easier testing and troubleshooting.  Occasionally it works right away but other times conflicts come up.  Generally once I have manage to confirm it works without the other code running I at least have a reasonable assumption that it may actually work and is wired properly.   Since I’m pretty new to the whole wiring these things up it’s a pretty good idea to test my wiring out.  So far I’ve actually done pretty well reading enough about each sensor to figure out what I need to make it work the first time.  If I go too long not getting it to work I try to disconnect everything else and run it by itself which usually helps me identify conflicting pin usage that I didn’t see initially.

So far I tend to find issues with the LCD interface / graphic chip / memory config chip to conflict with a particular pin here and there.  If it works without the LCD boards attached it obviously has a much smaller number of pins from the new sensor to try to find a conflict with. Usually by the time I isolate the LCD away from the system I’ve managed to throw together code that works within minutes of starting things up again.
My last success with the SD memory was short lived because I discovered there were pins that I had not noticed on the SSD1926 that apparently do something even though I’m in 8 bit mode instead of 16 bit.  They seem to have ended up being connected when I was trying to check my Write Protect and Card Detect pins.   It took probably about 3 hours of looking at the schematic for the graphics board assembly to figure out which wires (15 minutes) it was and then find some (the rest of the time) that were not being used already.   Since I am using 8 bit communication instead of  the 16 bit mode I would have assumed them to be “dormant” and potentially available.   Not quite sure what is going on with that since I have not obtained the data sheet for the SSD1926 chip yet.

I had an unexpected guest show up early in the week and didnt get much time to work on this.  After making a few adjustments to the wiring I got it up and writing to the SD with the LCD attached.  This weekend I got it loaded inside the Coffee Roaster programming.  I ran into a few initialization problems that resulted in a momentary “stream of gibberish” coming out the UART port that I was using for watching status of some of the code I was troubleshooting with in a terminal window.  It seemed as if the system had a baud rate to the com port of the computer that suddenly “shifted” up and down a few times in the middle of the machine starting up and then returned to normal. After I removed some of the apparently duplicate excess code from the init area it resumed working normally.

I then had to move the “write to SD” down through the startup past the time and date retrieval area.  This results in accurate time/date stamps on the file now being written to the SD memory card.  I then began to modify the SD demo write into a command that builds the buffer data using a sprintf template inserting date and time on a line separated by commas and a few sections (with 0.00’s right now) for sensor data as well.  I’m going to bundle the write commands up into a function so that I can insert it into roaster loop as a external function.  Every time it samples the temperatures and other future sensors it will shove it into the call to the “write to SD” function where it will get formatted and append to the file it created during the initialization of a new roast loop.

As I said, I havent had much time to work on it this past week but probably tonight and tomorrow I’ll get significantly closer to figuring that part out and probably test running the roaster with nothing in it just to get some temperaturee logging as it goes up/down for a few seconds and then exit the roast to close it to check the accuracy. Then when I’m sure that’s working I’ll try to do a regular roast with it out in the kitchen and see if I can get “good numbers” that I can post.

If I can get that working then the next step will be to get a “file management” function going to come up with names of files to make them unique and maybe let me load the data into the system to preview it on a graph on the PIC32 LCD as well as delete files. THEN I get to start figuring out how to program it to control things by itself based on my normal data.  😀

User interface work.

So at this point I’ve gotten annoyed with the other temperature sensor and decided I might as well move ahead with the functional part of the roaster.  This means the first thing I needed to do is draw a main menu for options.

Main Menu

As you can see this lists Manual and Auto Roast.  My plan is to make it where the first option simply gives you a few readings and then lets you “drive” by sliding the controls around.   I would make it log the information of what you set things to and what you got back from the system and perhaps let you “store” the settings to play them again as a profile.  That is where the next phase comes in, the Auto Roast.

I expect Auto Roast to be a portion of the system that would let you choose to either A) load a previous profile, or B) let the roaster pretty much run itself using a basic model of “drying” at a lower temperature for the first few minutes at a high fan speed and then begin to lower the fan speed and raise the temperature responding based on the time into the roast vs the temperature.  Expectations of driving first crack and the end of the roast based on a desired result would vary how it would work.  I’d anticipate some sort of yes/no 1/2/3/4 etc sort of question and answer series immediately before the roast activates.  While it would be mostly automatic you can step in at any time and seize control of a particular setting.

Main roasting screen

At this time the roasting system only monitors.  I have yet to work on actually connecting it directly to any of the controls on the roaster.  This will come later when there are more and better controls implemented.  Currently it simply shows bean temperature in Fahrenheit.  I will add the option to switch the temperatures on the Settings option from the main menu.  It also has a slighly inaccurate timer.  It seems to gain a second or two over the system clock in the corner every 40-60 seconds.  I need to work on the prioritization of the interrupts in the system and implement a series of if/else and/or case statements where I can service temperature, screen updates, and time tracking and use all of those checks as part of the delays required reading various sensors etc.  For example if it takes 100ns to service one sensor telling it to read a temperature or something but I need to wait 100ns to do another function then I can initiate the read request, perform the other function, and then return at the end to pickup the temperature result.  Some functions are more critical so they will take priority over other functions.  Those functions will take place on a tighter schedule while the other functions will “squeeze in” anywhere they can and take place based on a “true/false” tracking of whether they’ve run recently.  Once everything has run then everything will reset and things will start looping again.

The roast control system also has a series of buttons down the bottom for returning to the main menu, adding or removing time from the timer, as well as buttons for heat and fan control.  I expect to put more sensor readings as time goes on to display on the empty space.  I’m hoping to get the fan and heat controls to pop up over top of the roasting screen, allow adjustments, and then drop back to the bottom “tray”.

Graphing Temperatures from the MAX6675 on PIC32

Turns out graphing temp data is pretty simple.

Using the standard Graphics Library from Microchip just to display the output right now. Ultimately it’s working pretty much as necessary to show temperature graphically. I need to be able to adjust the top/bottom a little better using some formulas to come up with a scaling percentage dynamically to make it fit the minimum and maximum possible temperatures into the display without squishing it too much. Additionally I need to decide how quickly to scroll from left to right and possibly a way to redraw scrolling backwards to see starting graphs and archive the raw data to be reanalyzed later possibly zooming etc.

The input to the system is using a development board by Ryan J McLaughlin (dot com). The board was designed to be connected up to Arduino microprocessors but I figured out it could be plugged up directly to a PIC32 too. I decided I needed an easy to interface board with a thermocouple socket already on the board and this one fit the bill nicely.

image

Right now it blinks the status LED every time it makes a reading which is somewhere around 2-3 times per second.

MAX6675 with PIC32MX795F512L

As I mentioned earlier I’m using the USB Starter Kit II, the PIC32 Expansion Board, the SSD1926 PicTail Plus board, and a Truly 3.2″ 320×240 LCD display board to develop the roaster system. This has resulted in some “fun” trying to figure out which pins are really going where on the board and the PicTail cards that you can build your own circuits on. Occasionally some of the pins are not exactly labeled the right way or else there are a few pins that are wired together on the circuit boards making you unable to use one of the pins that are wired together or in some cases both cannot be used etc.

I’ve been working through various demos and trying to understand some of the libraries and still trying to identify all of the pins on the expansion board that are already attached to the LCD / graphics chip. So far I have not found any that involved the SPI1 Pins, which I’m sure is incorrect now.

I’ve now managed to get real time readings to occur while using SPI2 instead of SPI1. Originally I was using pins B2 (SS1), C4 (SDI1) , and D10 (SCK1). to communicate with the MAX6675 thermocouple. When the system launched it would begin to read temperatures from those pins properly but only while in animate debug mode. As soon as I would let it run in full speed to get to a break point later it would be partially or completely erroneous in the received readings. I’ve now switched it to the SPI2 pins and using G9 (SCK1), and G7 (SDI1). (The MAX6675 does not use the SDO pins since it only transmits readings and does not receive using SPI data)

I’m now opening the SPI port to communicate with the MAX6675 using 16bit word mode:
OpenSPI2(SPI_MODE16_ON | SPI_SMP_ON | SPI_CKE_ON | MASTER_ENABLE_ON | CLK_POL_ACTIVE_HIGH | SEC_PRESCAL_8_1 | PRI_PRESCAL_16_1, SPI_ENABLE);

[After I clean up all the “Dead code” that I’ve been testing various things with I’ll insert some additional SPI stuff HERE]

Which appears to work properly talking to the MAX6675. Further I’ve gotten the text to display on the screen of the current temperature where it runs a rolling average of the last 3 readings updating the screen after each additional reading. At the moment it flips on one of the starter kit’s LEDs based on the temperature when it needs to heat and turns it off when it’s reached a preset temperature.

I need to work more on getting the LCD display to show the activity that is going on in terms of heating/cooling and run a timer to begin estimating what stage the roast would be in based on temperatures and time-wise. Additionally I’ll need to figure out how to graph the temperature across the bottom of the screen too. I’m thinking screen real estate is somewhat limited so I may want to upgrade the LCD to the wider board to move some of the data to the side leaving a larger graph area to represent the roast curves.

Let me tell you about the time….

So I’ve ordered a plethora of stuff lately. Yesterday the 5×7 magnifier came. I’m figuring out I have no place to work on this stuff properly so it’s sort of wedged on my desk, and then today a box from Mouser showed up. In it I’ve determined I purchased the wrong AC adapter…. so now I need to order another one but this is for a slightly later stage so it can wait a little. Plus I believe I have a power supply I used on a fan to keep the air moving in my indoor orchid tray and lights area that is not being used currently due to a different setup that I’ve already stripped the ends off that I could then use with the relay board I received from Bulgaria. I’ll probably find something else to use that power supply for later anyway.

Anyway, TODAY the Mouser box arrived. In it were a variety of 0603 sized capacitors. For those that don’t know what that means… they are .06 inches by .03 inches or approximately 1.5mm by .77mm give or take a few hundredths of a milimeter.

Today I learned that fluxes are awesome when soldering SMT devices. I managed to mount my 32.768 6pF crystal and some of the 11pF 0603 capacitors from the selection but it was an adventure. I’ve lost approximately 4-5 of them into the rug somewhere now. Two are now securely attached to the board. I got the first one out ok but lost the second one immediately. I got a third one out but it didnt make it to the table and went straight for the rug. I recovered one of them from the rug and then tried to get it soldered onto the board. Two of them blew away using the hot air system. Once I got a corner tacked down properly it went much smoother. After allowing things to cool off I mounted the USB II Microchip board back into the IO board and connected to my LCD and fired it up. Immediately the clock on the display started ticking off seconds.

I had quite a bit of difficulty getting the soldering stuff going. I looked up temperatures for things on Wikipedia and ended up grossly under heating things up. I ended up looking up the soldering station’s manual on the internet since I couldn’t actually find it right now due to the bags and bags and boxes of parts and shipping materials everywhere. Once I finished looking that over things melted much more easily and started acting more normally. Once I started packing the parts away into boxes I discovered the real manual buried in the pile.

As mentioned the timer is running just fine. I am waiting a few hours to see how far off the time is from my computer to get an idea of whether this has a slight or a significant drift. So far it looks quite good. Time will have to tell. ULTIMATELY being REASONABLY close over a few minutes is fine. In the final project I will be using a DS3232 I think it is as a time source to populate the microchip “RTCC” after powering the system down and then turning it back on. Microchip for whatever reason built a system that has marketing towards it having a Real Time Clock built in. The problem is it doesn’t keep time when you turn it off due to having no backup battery of any kind. As a result it needs to be set every time you apply power to the system and then take it away when you turn it off.

Since I intend to hook this to the internet / router eventually I will try to implement a NTP client to set time into the DS3232 and then from there into the Microchip PIC32 while it runs. I’ve now manually adjusted the clock to be in sync (visibly anyway) with an atomic clock synced clock I have here immediately next to it. I set it at 10:12 so I will check it again in a few hours. The longer it seems stable the less I’ll have to make it lookup from the Dallas chip…..

I believe tomorrow I will be getting some ambient temperature, humidity, and barometric pressure sensors as well as a few other sensors I may or may not be experimenting around with too in this and other projects. So far 10 minutes in the clocks still seem synced so we’ll see what happens over the next few hours and overnight.

Oh… and Microchip never replied to my “technical support” request to get an idea what they suggested. I think the details I’ve found on the internet meant several different options of crystal and capacitor combo were ok and what they DESIGNED it with was not very common to find. I managed to find what it sounded like it was designed for though and so far so good.

I should start mounting the header pins this weekend and start hooking things to some of the external sensors to start getting readings into the programming. Once that happens I can start porting my PIC24 code over making a few adjustments and then start programming the roast curve tracking portion.

Early July Update. Observation on SR500.

Having been offered full time employment starting the middle of July after approximately 2 years of unemployment things are looking good for getting some progress on this project. LOL! While this may sound odd this is actually good due to the fact that I’m building (if all goes properly) a somewhat professional-esque coffee roasting computer. It takes a lot of money and resources to design this thing. I’m already into the project around $300-400 worth of circuit development kit gear and need a lot more stuff. In the end I’ll have a complete system that will be significantly cheaper to build but still have all the development kits to make other projects. I chose that route because of the “other projects” for down the road instead of only buying the things I need right now. While having full time employment will limit my available time it DOES however allow me money to keep purchasing all the parts.

Most projects you find on the internet for a coffee roaster use something like a Basic Stamp or some other very limited processor. It also usually involves hooking together a few things someone finds off eBay hooked together with some various wires and connectors salvaged off some old computer equipment and other devices abandoned in the garage. By the time it’s done you get a picture on the internet of some “finished” popcorn popper that looks like it’s about 30 seconds from taking out a corner of your house into a huge crater or like it’s some sort of industrial wiring project of conduit and electrical boxes.

I’m intending on making this thing as small as I can make it and sealing it up inside a electronics case with a single cord or perhaps a cord and a sensor wire that plugs into the back of the case that leads to the roaster. I don’t want 50 million little cords and sensors and clunky switches and other doo-dads spread across my counter. I also want to be able to pick the whole thing up and move it somewhere else without accidentally cracking off a wire and needing to re-solder it. I don’t know about you but I love my coffee. I don’t love having to re-solder the wiring just to roast some more or being unable to use my kitchen for anything else.

My Kitchen is not that big. It cannot accommodate a lot of “stuff” strewn around it. so the entire thing will need to be compact. As a result I intend on having a case that has a LCD touch screen installed. It will probably have a LED or two and at most probably a single power switch on the front edge or side. I will likely try to design the circuitry so that it fits onto one or more circuit boards stacked on top of one another. The LCD will be mounted on top with various connectors and other items stacked below it. I’m reasonably sure I can shrink the majority of this down into a space about 4″ by 6″ and about 1.5 to 2″ tall.

As mentioned I recently purchased the PIC32 development gear. At the moment I’ve been working on the GUI. This is a lot more complicated programming than I’m used to. Additionally I’m having a few “weird” situations where LED’s on the starter kit are lit that I don’t seem to understand why. When I turn on an LED that is normally off things work fine but then when I programmatically turn that one off the LCD turns off too though they shouldn’t be connected at all. The other LED works fine turning it on and off the same way. One of these LEDs simply stays on all the time no matter what.

At the moment I now have a “splash screen” functioning. I touch the screen and it continues to a “Home” menu. From there it offers several buttons to run the manual or the automatic roasting menu. There is also a provision for a Setup menu. I am still waiting for the ethernet to arrive that will allow me to download roasting data out of the system or pre-configure a roast from a web page. It currently draws temperature onto the screen from some “made up numbers” I have the thermocouple and the chip that will convert the sensor reading to numbers but need to solder it to a board that I can connect to the processor. I also need to do the same with the clock chip that I have as well. The processor has built in clock routines but they only work while the system is turned on. As soon as you cut power that clock loses it’s data. As a result I will program the system to read the clock chip every time the system turns on.

Over the next few days I will program the roasting screens to change certain display areas based on the simulated temperature numbers and then integrate the “control” portion where it then stops the increase in temperature and then tries to increase it appropriately. I still need to figure out the timer stuff… it doesnt seem to run on the demo and I was thinking it had to do with an oscillator being missing but this seems to be related to USB stuff in the documentation for the starter kit. This doesnt seem right though. I need to figure that out and then the next step is to start ordering all the pin headers and not included on some of the other boards. I’ll try to figure out a few more of the parts that I’ll need and order those in the next few days as well so I can keep working on this. Assuming I’m right that the crystal is required apparently Microchip decided to save 83 cents by not including the oscillator.

Also as a side note. Due to the job offer I completed a move to Northern California from Central California which has kept me from messing with the coffee much until now. A variety of coffee that I roasted here with the Fresh Roast +8 took approximately 6 minutes to hit second crack. Using a SR500 where I used to live took about 6 minutes as well while running the fan at half speed for the first two minutes. To do the same thing here with the SR500 appears to take around 7-8 minutes with a lot more slowing down the fan to around the 25% setting once movement starts to flow more easily and first crack was reached.

Parts received some not…

As mentioned some of the items had later ship dates than others. As of June 16th I have received the IO board, the prototype boards, the LCD graphics w/LCD kit, and a power supply.

In addition to the development kit I have on order a few engineering samples for a few parts to test out before I pick vendors to program things based on and start purchasing real parts. These engineering samples will be mounted on “prototyping” boards that will either be custom built or ordered off the internet pre-made. Occasionally chips are used in a variety of ways so I will simply build a board to solder them down to and install pin headers to attach to on the board. These will also serve as “test” printed circuit boards as I learn to make boards on my own.

The ones I have received so far are a chip that has a real time clock/calendar in it and a chip that reads temperatures from a thermocouple probe. I still have requests out for a few ambient air temperature sensors and a few other things that will be used in additional projects that will eventually connect to/from the roaster computer.

The surprising part is that the clock chip is more or less around the size I expected (about guy little/pinky finger nail sized) BUT that the temperature chip is significantly smaller than I expected. It’s REALLY small. It’s so small that you could literally put at LEAST 16 of them on top of a single computer laptop keyboard key.

I am still waiting for the “brain” starter kit to arrive. This is where things get funky. When I ordered it the availability date for it and the ethernet card were listed as June 28th with an estimated delivery date of June 30th. This is good because I’ve got some free time from then until the middle of July so that arrival date was going to be good to let me work on things some. Today, though, I get this email. It now says that the ship date is changed to July 30th. My online invoice still shows the ship date as June 28th. The microchipdirect.com website says the availability date is July 2nd. So I’m thinking my chances of seeing this anytime soon are completely random and probably not likely.

Ordered parts this weekend for roaster controller.

I’ve ordered some parts from Maxim/Dallas as well as from Microchip this past weekend. The stuff from Maxim is supposed to be coming US Postal Service so I don’t really know when they will arrive. I forgot to add a temperature sensor (ambient) to the order though so I will need to come back to that later. I need to compare it with a similar chip offered by Microchip to see which one I want to use. I believe the chips by Microchip are actually smaller and more accurate but I will need to confirm later.

According to Microchip’s website / my invoice the IO board, graphics board and LCD touch screen, Prototype cards, and a 9V Power Supply will ship sometime in the next couple days. They are scheduled for arrival on the 17th. The Network Card and PIC32 Starter Kit is not due to be available for 2 weeks and is supposed to arrive on the 30th.

Building a roast controller system.

As alluded to earlier in the blog I am intending on building a roaster controller system.  I’m probably a bit of an over-achiever in terms of my projects because every time I create something on the internet for one of my websites, as part of a building project in the yard, or whatever else I’m creating I always over-analyze it.  In my career one of the areas I’ve been responsible for was “Disaster Recovery” planning for computer systems.  In other words my job was to over-analyze all the things that could go wrong and figure out a plan to deal with them.  At the same time I also have to plan all the ways for it to go right and have a plan so anyone can do it even without strong computer skills.

Focusing on a roast controller as mentioned I’ve already purchased some testing equipment for measuring temperature using a K type thermocouple. I am now finalizing the equipment that I’m going to use to build this and test it.  I’ve focused on using the PIC32 microprocessor due to its abilities to work easily with Ethernet, LCDs, and having many input/output circuits.  In addition it seems to be a robust platform for RTOS systems allowing a lot to be going on all at the same time.

To ease development I am choosing to embrace the development tools provided by the manufacturer.  This of course adds to the startup cost of the system but allows me to “try new things” in the future too using the development platform.  Once I finalize the project I would then order the individual components and manufacture my own circuit boards.  To start off I expect to need the following.

The Starting Parts

  1. DM320003-2 – PIC32 USB Starter Kit II – $55.00

    • Main processor (MCU) test board.
    • Contains PIC32MX795F512L processor.
    • 80 MHz with 512K Flash, 128K RAM. (this is actually a lot for a simple coffee roaster but is necessary for drawing graphical LCD, developing complex roasting profiles, and loading Ethernet overhead.)
    • Allows USB, Ethernet, LCD, I2C and SPI communications. 
  2. DM320002 – PIC32 I/O Expansion Board – $72.00

    • Connector to access pins and interface auxiliary boards.
  3. AC164132 – Fast 100Mbps Ethernet PICtail Plus Daughter Board –$49.99

    • Physical wired ethernet board for interface to DM320002.
  4. AC164126 – Prototype PICtail Plus Daughter Board – $20.00
    • Prototype boards to solder additional parts and extensions such as temperature probe chips, time devices, relays, etc.
  5. AC164127-3 – Graphics PICtail Plus Daughter Board with 3.2 Display Kit – $154.99

    • SSD1926 Graphics chip (kind of like a video card)
    • 3.2 QVGA (240X320) TFT LCD with 18-bit parallel RGB interface
    • Touch Screen

The Later Parts

The above parts allow me to start testing User Interface functionality without worrying too much about the circuit boards except for the occasional prototype board communicating with a sensor or two.  I’m doing that to determine the final touch screen configuration and “what is possible” on the screen real estate to determine if I want to pursue additional sensors and features.  It will also allow me to begin testing response time of various sensors on the prototype boards.  Some parts I expect to need:

  1. MAX6676 Thermocouple Amplifier
  2. DS3232 Real Time Clock
  3. Lots of resistors
  4. Lots of capcitors
  5. Various Transistors
  6. Lots of diodes
  7. Photosensitive PCBs
  8. PCB etch Chemicals and developer
  9. SMD soldering and hot air rework station
  10. Infrared circuit board pre-heater station
  11. Small Drill Press w/ bits for drilling PCBs
  12. Oscilloscope for dimmer testing
  13. Several relays and/or some dimmer circuits that need to be designed still.
  14. Probably a video camera at some point to demonstrate progress/results.